Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make sure uninitialised exports turn up via .hasOwnProperty for non-E…
…S formats (#3957)
- Loading branch information
1 parent
45d8e5e
commit 3394ae9
Showing
20 changed files
with
109 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import Variable from '../ast/variables/Variable'; | ||
|
||
export function isReassignedExportsMember( | ||
variable: Variable, | ||
exportNamesByVariable: Map<Variable, string[]> | ||
): boolean { | ||
return ( | ||
variable.renderBaseName !== null && exportNamesByVariable.has(variable) && variable.isReassigned | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
test/form/samples/render-named-export-declarations/_expected/amd.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
test/form/samples/render-named-export-declarations/_expected/iife.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
test/function/samples/create-undefined-export-property-compact/_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const assert = require('assert'); | ||
|
||
module.exports = { | ||
description: 'creates an export as an exports property even if is has no initializer', | ||
options: { output: { compact: true } }, | ||
exports(exports) { | ||
assert.strictEqual(exports.foo, undefined); | ||
assert.strictEqual(exports.bar, undefined); | ||
assert.strictEqual(exports.baz, undefined); | ||
assert.ok(exports.hasOwnProperty('foo')); | ||
assert.ok(exports.hasOwnProperty('bar')); | ||
assert.ok(exports.hasOwnProperty('baz')); | ||
exports.defineFooBar(); | ||
assert.strictEqual(exports.foo, 'defined'); | ||
assert.strictEqual(exports.bar, 'defined'); | ||
} | ||
}; |
6 changes: 6 additions & 0 deletions
6
test/function/samples/create-undefined-export-property-compact/main.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export let foo; | ||
export let bar, quux = 3, baz; | ||
export function defineFooBar() { | ||
foo = 'defined'; | ||
bar = 'defined'; | ||
} |
16 changes: 16 additions & 0 deletions
16
test/function/samples/create-undefined-export-property/_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const assert = require('assert'); | ||
|
||
module.exports = { | ||
description: 'creates an export as an exports property even if is has no initializer', | ||
exports(exports) { | ||
assert.strictEqual(exports.foo, undefined); | ||
assert.strictEqual(exports.bar, undefined); | ||
assert.strictEqual(exports.baz, undefined); | ||
assert.ok(exports.hasOwnProperty('foo')); | ||
assert.ok(exports.hasOwnProperty('bar')); | ||
assert.ok(exports.hasOwnProperty('baz')); | ||
exports.defineFooBar(); | ||
assert.strictEqual(exports.foo, 'defined'); | ||
assert.strictEqual(exports.bar, 'defined'); | ||
} | ||
}; |
6 changes: 6 additions & 0 deletions
6
test/function/samples/create-undefined-export-property/main.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export let foo; | ||
export let bar, quux = 3, baz; | ||
export function defineFooBar() { | ||
foo = 'defined'; | ||
bar = 'defined'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
description: 'handles loops with destructuring declarations' | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
let result; | ||
|
||
for (const [foo] of [['foo']]) { | ||
result = foo; | ||
} | ||
assert.strictEqual(result, 'foo'); | ||
|
||
for (const { bar } of [{ bar: 'bar' }]) { | ||
result = bar; | ||
} | ||
assert.strictEqual(result, 'bar'); |