From f09c0f21f756f4ed16082ad7e2a2b09061178f21 Mon Sep 17 00:00:00 2001 From: Beknar Askarov Date: Sat, 7 Sep 2019 20:06:11 +0200 Subject: [PATCH] fix: remove 'use strict'; from systemjs when strict=false --- src/finalisers/system.ts | 2 +- test/form/samples/strict-false/_config.js | 8 ++++++++ .../form/samples/strict-false/_expected/amd.js | 13 +++++++++++++ .../form/samples/strict-false/_expected/cjs.js | 9 +++++++++ test/form/samples/strict-false/_expected/es.js | 9 +++++++++ .../samples/strict-false/_expected/iife.js | 12 ++++++++++++ .../samples/strict-false/_expected/system.js | 18 ++++++++++++++++++ .../form/samples/strict-false/_expected/umd.js | 15 +++++++++++++++ test/form/samples/strict-false/main.js | 9 +++++++++ 9 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 test/form/samples/strict-false/_config.js create mode 100644 test/form/samples/strict-false/_expected/amd.js create mode 100644 test/form/samples/strict-false/_expected/cjs.js create mode 100644 test/form/samples/strict-false/_expected/es.js create mode 100644 test/form/samples/strict-false/_expected/iife.js create mode 100644 test/form/samples/strict-false/_expected/system.js create mode 100644 test/form/samples/strict-false/_expected/umd.js create mode 100644 test/form/samples/strict-false/main.js 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