diff --git a/src/finalisers/system.ts b/src/finalisers/system.ts index 1eb45f65d43..375143c0188 100644 --- a/src/finalisers/system.ts +++ b/src/finalisers/system.ts @@ -173,7 +173,7 @@ export default function system( let wrapperStart = `System.register(${registeredName}[` + dependencyIds.join(`,${_}`) + - `],${_}function${_}(${wrapperParams})${_}{${n}${t}'use strict';` + + `],${_}function${_}(${wrapperParams})${_}{${n}${t}${options.strict ? "'use strict';" : ''}` + getStarExcludesBlock(starExcludes, varOrConst, _, t, n) + getImportBindingsBlock(importBindings, _, t, n) + `${n}${t}return${_}{${ diff --git a/test/form/samples/strict-false/_config.js b/test/form/samples/strict-false/_config.js new file mode 100644 index 00000000000..dac5b866925 --- /dev/null +++ b/test/form/samples/strict-false/_config.js @@ -0,0 +1,8 @@ +module.exports = { + description: 'use strict should not be present', + options: { + output: { + strict: false + } + } +}; diff --git a/test/form/samples/strict-false/_expected/amd.js b/test/form/samples/strict-false/_expected/amd.js new file mode 100644 index 00000000000..374a89b69eb --- /dev/null +++ b/test/form/samples/strict-false/_expected/amd.js @@ -0,0 +1,13 @@ +define(function () { + + const localVariable = 'local'; + + try { + globalVariable = localVariable; + } catch (error) { + console.log('use strict; detected', error); + + Function("g", "globalVariable = g")(localVariable); + } + +}); diff --git a/test/form/samples/strict-false/_expected/cjs.js b/test/form/samples/strict-false/_expected/cjs.js new file mode 100644 index 00000000000..bd207c44a45 --- /dev/null +++ b/test/form/samples/strict-false/_expected/cjs.js @@ -0,0 +1,9 @@ +const localVariable = 'local'; + +try { + globalVariable = localVariable; +} catch (error) { + console.log('use strict; detected', error); + + Function("g", "globalVariable = g")(localVariable); +} diff --git a/test/form/samples/strict-false/_expected/es.js b/test/form/samples/strict-false/_expected/es.js new file mode 100644 index 00000000000..bd207c44a45 --- /dev/null +++ b/test/form/samples/strict-false/_expected/es.js @@ -0,0 +1,9 @@ +const localVariable = 'local'; + +try { + globalVariable = localVariable; +} catch (error) { + console.log('use strict; detected', error); + + Function("g", "globalVariable = g")(localVariable); +} diff --git a/test/form/samples/strict-false/_expected/iife.js b/test/form/samples/strict-false/_expected/iife.js new file mode 100644 index 00000000000..5e3ed9081ea --- /dev/null +++ b/test/form/samples/strict-false/_expected/iife.js @@ -0,0 +1,12 @@ +(function () { + const localVariable = 'local'; + + try { + globalVariable = localVariable; + } catch (error) { + console.log('use strict; detected', error); + + Function("g", "globalVariable = g")(localVariable); + } + +}()); diff --git a/test/form/samples/strict-false/_expected/system.js b/test/form/samples/strict-false/_expected/system.js new file mode 100644 index 00000000000..2ed282add3d --- /dev/null +++ b/test/form/samples/strict-false/_expected/system.js @@ -0,0 +1,18 @@ +System.register([], function () { + + return { + execute: function () { + + const localVariable = 'local'; + + try { + globalVariable = localVariable; + } catch (error) { + console.log('use strict; detected', error); + + Function("g", "globalVariable = g")(localVariable); + } + + } + }; +}); diff --git a/test/form/samples/strict-false/_expected/umd.js b/test/form/samples/strict-false/_expected/umd.js new file mode 100644 index 00000000000..6db1e8e95a6 --- /dev/null +++ b/test/form/samples/strict-false/_expected/umd.js @@ -0,0 +1,15 @@ +(function (factory) { + typeof define === 'function' && define.amd ? define(factory) : + factory(); +}(function () { + const localVariable = 'local'; + + try { + globalVariable = localVariable; + } catch (error) { + console.log('use strict; detected', error); + + Function("g", "globalVariable = g")(localVariable); + } + +})); diff --git a/test/form/samples/strict-false/main.js b/test/form/samples/strict-false/main.js new file mode 100644 index 00000000000..ee565e65983 --- /dev/null +++ b/test/form/samples/strict-false/main.js @@ -0,0 +1,9 @@ +const localVariable = 'local' + +try { + globalVariable = localVariable; +} catch (error) { + console.log('use strict; detected', error); + + Function("g", "globalVariable = g")(localVariable); +} \ No newline at end of file