Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option to prevent code for external live bindings (#3010)
* Add option to not generate code for external live bindings * Update documentation * Increase timeouts
- Loading branch information
1 parent
def3ae2
commit 4a0fa56
Showing
32 changed files
with
341 additions
and
68 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,22 +1,34 @@ | ||
import { INTEROP_NAMESPACE_VARIABLE } from '../../utils/variableNames'; | ||
|
||
export function getInteropNamespace(_: string, n: string, t: string) { | ||
return `function ${INTEROP_NAMESPACE_VARIABLE}(e)${_}{${n}` + | ||
`${t}if${_}(e${_}&&${_}e.__esModule)${_}{${_}return e;${_}}${_}else${_}{${n}` + | ||
`${t}${t}var n${_}=${_}{};${n}` + | ||
`${t}${t}if${_}(e)${_}{${n}` + | ||
`${t}${t}${t}Object.keys(e).forEach(function${_}(k)${_}{${n}` + | ||
`${t}${t}${t}${t}var d${_}=${_}Object.getOwnPropertyDescriptor(e,${_}k);${n}` + | ||
`${t}${t}${t}${t}Object.defineProperty(n,${_}k,${_}d.get${_}?${_}d${_}:${_}{${n}` + | ||
`${t}${t}${t}${t}${t}enumerable:${_}true,${n}` + | ||
`${t}${t}${t}${t}${t}get:${_}function${_}()${_}{${n}` + | ||
`${t}${t}${t}${t}${t}${t}return e[k];${n}` + | ||
`${t}${t}${t}${t}${t}}${n}` + | ||
`${t}${t}${t}${t}});${n}` + | ||
`${t}${t}${t}});${n}` + | ||
`${t}${t}}${n}` + | ||
`${t}${t}n['default']${_}=${_}e;${n}` + | ||
`${t}${t}return n;${n}` + | ||
`${t}}${n}` + | ||
`}${n}${n}`; | ||
function copyPropertyLiveBinding(_: string, n: string, t: string, i: string) { | ||
return ( | ||
`${i}var d${_}=${_}Object.getOwnPropertyDescriptor(e,${_}k);${n}` + | ||
`${i}Object.defineProperty(n,${_}k,${_}d.get${_}?${_}d${_}:${_}{${n}` + | ||
`${i}${t}enumerable:${_}true,${n}` + | ||
`${i}${t}get:${_}function${_}()${_}{${n}` + | ||
`${i}${t}${t}return e[k];${n}` + | ||
`${i}${t}}${n}` + | ||
`${i}});${n}` | ||
); | ||
} | ||
|
||
function copyPropertyStatic(_: string, n: string, _t: string, i: string) { | ||
return `${i}n[k]${_}=e${_}[k];${n}`; | ||
} | ||
|
||
export function getInteropNamespace(_: string, n: string, t: string, liveBindings: boolean) { | ||
return ( | ||
`function ${INTEROP_NAMESPACE_VARIABLE}(e)${_}{${n}` + | ||
`${t}if${_}(e${_}&&${_}e.__esModule)${_}{${_}return e;${_}}${_}else${_}{${n}` + | ||
`${t}${t}var n${_}=${_}{};${n}` + | ||
`${t}${t}if${_}(e)${_}{${n}` + | ||
`${t}${t}${t}Object.keys(e).forEach(function${_}(k)${_}{${n}` + | ||
(liveBindings ? copyPropertyLiveBinding : copyPropertyStatic)(_, n, t, t + t + t + t) + | ||
`${t}${t}${t}});${n}` + | ||
`${t}${t}}${n}` + | ||
`${t}${t}n['default']${_}=${_}e;${n}` + | ||
`${t}${t}return n;${n}` + | ||
`${t}}${n}` + | ||
`}${n}${n}` | ||
); | ||
} |
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
11 changes: 11 additions & 0 deletions
11
test/form/samples/no-external-live-bindings-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,11 @@ | ||
module.exports = { | ||
description: 'Allows omitting the code that handles external live bindings in compact mode', | ||
options: { | ||
external: () => true, | ||
output: { | ||
compact: true, | ||
externalLiveBindings: false, | ||
name: 'bundle' | ||
} | ||
} | ||
}; |
1 change: 1 addition & 0 deletions
1
test/form/samples/no-external-live-bindings-compact/_expected/amd.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
test/form/samples/no-external-live-bindings-compact/_expected/cjs.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
test/form/samples/no-external-live-bindings-compact/_expected/es.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 @@ | ||
export{external1}from'external1';export*from'external2';const dynamic = import('external3');export{dynamic}; |
1 change: 1 addition & 0 deletions
1
test/form/samples/no-external-live-bindings-compact/_expected/iife.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
test/form/samples/no-external-live-bindings-compact/_expected/system.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
test/form/samples/no-external-live-bindings-compact/_expected/umd.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 @@ | ||
export { external1 } from 'external1'; | ||
export * from 'external2'; | ||
export const dynamic = import('external3'); |
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 @@ | ||
module.exports = { | ||
description: 'Allows omitting the code that handles external live bindings', | ||
options: { | ||
external: () => true, | ||
output: { | ||
externalLiveBindings: false, | ||
name: 'bundle' | ||
} | ||
} | ||
}; |
26 changes: 26 additions & 0 deletions
26
test/form/samples/no-external-live-bindings/_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
define(['require', 'exports', 'external1', 'external2'], function (require, exports, external1, external2) { 'use strict'; | ||
|
||
function _interopNamespace(e) { | ||
if (e && e.__esModule) { return e; } else { | ||
var n = {}; | ||
if (e) { | ||
Object.keys(e).forEach(function (k) { | ||
n[k] =e [k]; | ||
}); | ||
} | ||
n['default'] = e; | ||
return n; | ||
} | ||
} | ||
|
||
const dynamic = new Promise(function (resolve, reject) { require(['external3'], function (m) { resolve(_interopNamespace(m)); }, reject) }); | ||
|
||
Object.keys(external2).forEach(function (k) { | ||
if (k !== 'default') exports[k] = external2[k]; | ||
}); | ||
exports.external1 = external1.external1; | ||
exports.dynamic = dynamic; | ||
|
||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
|
||
}); |
27 changes: 27 additions & 0 deletions
27
test/form/samples/no-external-live-bindings/_expected/cjs.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,27 @@ | ||
'use strict'; | ||
|
||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
|
||
function _interopNamespace(e) { | ||
if (e && e.__esModule) { return e; } else { | ||
var n = {}; | ||
if (e) { | ||
Object.keys(e).forEach(function (k) { | ||
n[k] =e [k]; | ||
}); | ||
} | ||
n['default'] = e; | ||
return n; | ||
} | ||
} | ||
|
||
var external1 = require('external1'); | ||
var external2 = require('external2'); | ||
|
||
const dynamic = new Promise(function (resolve) { resolve(_interopNamespace(require('external3'))); }); | ||
|
||
Object.keys(external2).forEach(function (k) { | ||
if (k !== 'default') exports[k] = external2[k]; | ||
}); | ||
exports.external1 = external1.external1; | ||
exports.dynamic = dynamic; |
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 { external1 } from 'external1'; | ||
export * from 'external2'; | ||
|
||
const dynamic = import('external3'); | ||
|
||
export { dynamic }; |
Oops, something went wrong.