-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Properly export destructured export declarations in SystemJS (#2587)
* Properly export destructured export declarations in SystemJS * Update systemJS exports in destructuring assignments via injecting an IIFE
- Loading branch information
1 parent
f58d1e6
commit 371aa62
Showing
16 changed files
with
171 additions
and
34 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
import { WritableEntity } from '../../Entity'; | ||
import Variable from '../../variables/Variable'; | ||
import { Node } from './Node'; | ||
|
||
export interface PatternNode extends WritableEntity, Node {} | ||
export interface PatternNode extends WritableEntity, Node { | ||
addExportedVariables(variables: Variable[]): void; | ||
} |
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,12 @@ | ||
import Variable from '../ast/variables/Variable'; | ||
|
||
export function getSystemExportStatement(exportedVariables: Variable[]): string { | ||
if (exportedVariables.length === 1) { | ||
return `exports('${exportedVariables[0].safeExportName || | ||
exportedVariables[0].exportName}', ${exportedVariables[0].getName()});`; | ||
} else { | ||
return `exports({${exportedVariables | ||
.map(variable => `${variable.safeExportName || variable.exportName}: ${variable.getName()}`) | ||
.join(', ')}});`; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
test/form/samples/system-export-destructuring-assignment/_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,8 @@ | ||
module.exports = { | ||
description: 'supports destructuring assignments of exports for systemJS', | ||
options: { | ||
output: { | ||
format: 'system' | ||
} | ||
} | ||
}; |
19 changes: 19 additions & 0 deletions
19
test/form/samples/system-export-destructuring-assignment/_expected.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,19 @@ | ||
System.register([], function (exports, module) { | ||
'use strict'; | ||
return { | ||
execute: function () { | ||
|
||
exports({ | ||
a: void 0, | ||
b: void 0, | ||
c: void 0 | ||
}); | ||
|
||
let a, b, c; | ||
|
||
console.log(function (v) {exports('a', a); return v;} ({a} = someObject)); | ||
(function (v) {exports({b: b, c: c}); return v;} ({b, c} = someObject)); | ||
|
||
} | ||
}; | ||
}); |
4 changes: 4 additions & 0 deletions
4
test/form/samples/system-export-destructuring-assignment/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,4 @@ | ||
export let a, b, c; | ||
|
||
console.log({a} = someObject); | ||
({b, c} = someObject); |
8 changes: 8 additions & 0 deletions
8
test/form/samples/system-export-destructuring-declaration/_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,8 @@ | ||
module.exports = { | ||
description: 'supports destructuring declarations for systemJS', | ||
options: { | ||
output: { | ||
format: 'system' | ||
} | ||
} | ||
}; |
15 changes: 15 additions & 0 deletions
15
test/form/samples/system-export-destructuring-declaration/_expected.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,15 @@ | ||
System.register([], function (exports, module) { | ||
'use strict'; | ||
return { | ||
execute: function () { | ||
|
||
const {a = 1, ...b} = global1, c = exports('c', global2), {d} = global3; exports({a: a, b: b, d: d}); | ||
const [e, ...f] = global4; exports({e: e, f: f}); | ||
const {g, x: h = 2, y: {z: i}, a: [j ,k,, l]} = global5; exports({g: g, h: h, i: i, j: j, k: k, l: l}); | ||
|
||
var m = exports('m', 1); | ||
var {m} = global6; exports('m', m); | ||
|
||
} | ||
}; | ||
}); |
6 changes: 6 additions & 0 deletions
6
test/form/samples/system-export-destructuring-declaration/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 const {a = 1, ...b} = global1, c = global2, {d} = global3; | ||
export const [e, ...f] = global4; | ||
export const {g, x: h = 2, y: {z: i}, a: [j ,k,, l]} = global5; | ||
|
||
export var m = 1; | ||
var {m} = global6; |