Skip to content

Commit

Permalink
fix: remove 'use strict'; from systemjs when strict=false (#3101)
Browse files Browse the repository at this point in the history
  • Loading branch information
Beknar Askarov authored and lukastaegert committed Sep 8, 2019
1 parent 8dceaf6 commit d13cb90
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/finalisers/system.ts
Expand Up @@ -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${_}{${
Expand Down
8 changes: 8 additions & 0 deletions test/form/samples/strict-false/_config.js
@@ -0,0 +1,8 @@
module.exports = {
description: 'use strict should not be present',
options: {
output: {
strict: false
}
}
};
13 changes: 13 additions & 0 deletions 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);
}

});
9 changes: 9 additions & 0 deletions 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);
}
9 changes: 9 additions & 0 deletions 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);
}
12 changes: 12 additions & 0 deletions 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);
}

}());
18 changes: 18 additions & 0 deletions 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);
}

}
};
});
15 changes: 15 additions & 0 deletions 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);
}

}));
9 changes: 9 additions & 0 deletions 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);
}

0 comments on commit d13cb90

Please sign in to comment.