Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update systemJS exports in destructuring assignments via injecting an…
… IIFE
- Loading branch information
1 parent
27be520
commit 472c60f
Showing
10 changed files
with
76 additions
and
40 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
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(', ')}});`; | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
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
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
8 changes: 3 additions & 5 deletions
8
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 |
---|---|---|
@@ -1,6 +1,4 @@ | ||
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 let a, b, c; | ||
|
||
export var m = 1; | ||
var {m} = global6; | ||
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; |