From fb360039cea6c7e8e4f09458b518b1fcf45d0d74 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Mon, 2 Feb 2015 10:44:17 +1100 Subject: [PATCH] remap top level this to undefined - #562 --- lib/6to5/transformation/transformers/other/use-strict.js | 2 +- .../use-strict/illegal-this-root-call/options.json | 3 --- .../use-strict/illegal-this-root-declaration/options.json | 3 --- .../use-strict/illegal-this-root-reference/options.json | 3 --- .../actual.js | 0 .../use-strict/undefined-this-arrow-function/expected.js | 5 +++++ .../options.json | 0 .../actual.js | 0 .../use-strict/undefined-this-root-call/expected.js | 3 +++ .../actual.js | 0 .../use-strict/undefined-this-root-declaration/expected.js | 3 +++ .../actual.js | 0 .../use-strict/undefined-this-root-reference/expected.js | 3 +++ 13 files changed, 15 insertions(+), 10 deletions(-) delete mode 100644 test/fixtures/transformation/use-strict/illegal-this-root-call/options.json delete mode 100644 test/fixtures/transformation/use-strict/illegal-this-root-declaration/options.json delete mode 100644 test/fixtures/transformation/use-strict/illegal-this-root-reference/options.json rename test/fixtures/transformation/use-strict/{illegal-this-arrow-function => undefined-this-arrow-function}/actual.js (100%) create mode 100644 test/fixtures/transformation/use-strict/undefined-this-arrow-function/expected.js rename test/fixtures/transformation/use-strict/{illegal-this-arrow-function => undefined-this-arrow-function}/options.json (100%) rename test/fixtures/transformation/use-strict/{illegal-this-root-call => undefined-this-root-call}/actual.js (100%) create mode 100644 test/fixtures/transformation/use-strict/undefined-this-root-call/expected.js rename test/fixtures/transformation/use-strict/{illegal-this-root-declaration => undefined-this-root-declaration}/actual.js (100%) create mode 100644 test/fixtures/transformation/use-strict/undefined-this-root-declaration/expected.js rename test/fixtures/transformation/use-strict/{illegal-this-root-reference => undefined-this-root-reference}/actual.js (100%) create mode 100644 test/fixtures/transformation/use-strict/undefined-this-root-reference/expected.js diff --git a/lib/6to5/transformation/transformers/other/use-strict.js b/lib/6to5/transformation/transformers/other/use-strict.js index 3965a463de..2d3c6750bd 100644 --- a/lib/6to5/transformation/transformers/other/use-strict.js +++ b/lib/6to5/transformation/transformers/other/use-strict.js @@ -17,5 +17,5 @@ exports.FunctionExpression = function (node, parent, scope, context) { }; exports.ThisExpression = function (node, parent, scope, context, file) { - throw file.errorWithNode(node, "Top level `this` is `undefined` in strict mode", ReferenceError); + return t.identifier("undefined"); }; diff --git a/test/fixtures/transformation/use-strict/illegal-this-root-call/options.json b/test/fixtures/transformation/use-strict/illegal-this-root-call/options.json deleted file mode 100644 index 3137168db6..0000000000 --- a/test/fixtures/transformation/use-strict/illegal-this-root-call/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Top level `this` is `undefined` in strict mode" -} diff --git a/test/fixtures/transformation/use-strict/illegal-this-root-declaration/options.json b/test/fixtures/transformation/use-strict/illegal-this-root-declaration/options.json deleted file mode 100644 index 3137168db6..0000000000 --- a/test/fixtures/transformation/use-strict/illegal-this-root-declaration/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Top level `this` is `undefined` in strict mode" -} diff --git a/test/fixtures/transformation/use-strict/illegal-this-root-reference/options.json b/test/fixtures/transformation/use-strict/illegal-this-root-reference/options.json deleted file mode 100644 index 3137168db6..0000000000 --- a/test/fixtures/transformation/use-strict/illegal-this-root-reference/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Top level `this` is `undefined` in strict mode" -} diff --git a/test/fixtures/transformation/use-strict/illegal-this-arrow-function/actual.js b/test/fixtures/transformation/use-strict/undefined-this-arrow-function/actual.js similarity index 100% rename from test/fixtures/transformation/use-strict/illegal-this-arrow-function/actual.js rename to test/fixtures/transformation/use-strict/undefined-this-arrow-function/actual.js diff --git a/test/fixtures/transformation/use-strict/undefined-this-arrow-function/expected.js b/test/fixtures/transformation/use-strict/undefined-this-arrow-function/expected.js new file mode 100644 index 0000000000..bf107937df --- /dev/null +++ b/test/fixtures/transformation/use-strict/undefined-this-arrow-function/expected.js @@ -0,0 +1,5 @@ +"use strict"; + +var foo = function () { + return undefined; +}; \ No newline at end of file diff --git a/test/fixtures/transformation/use-strict/illegal-this-arrow-function/options.json b/test/fixtures/transformation/use-strict/undefined-this-arrow-function/options.json similarity index 100% rename from test/fixtures/transformation/use-strict/illegal-this-arrow-function/options.json rename to test/fixtures/transformation/use-strict/undefined-this-arrow-function/options.json diff --git a/test/fixtures/transformation/use-strict/illegal-this-root-call/actual.js b/test/fixtures/transformation/use-strict/undefined-this-root-call/actual.js similarity index 100% rename from test/fixtures/transformation/use-strict/illegal-this-root-call/actual.js rename to test/fixtures/transformation/use-strict/undefined-this-root-call/actual.js diff --git a/test/fixtures/transformation/use-strict/undefined-this-root-call/expected.js b/test/fixtures/transformation/use-strict/undefined-this-root-call/expected.js new file mode 100644 index 0000000000..269a449b01 --- /dev/null +++ b/test/fixtures/transformation/use-strict/undefined-this-root-call/expected.js @@ -0,0 +1,3 @@ +"use strict"; + +undefined.foo(); \ No newline at end of file diff --git a/test/fixtures/transformation/use-strict/illegal-this-root-declaration/actual.js b/test/fixtures/transformation/use-strict/undefined-this-root-declaration/actual.js similarity index 100% rename from test/fixtures/transformation/use-strict/illegal-this-root-declaration/actual.js rename to test/fixtures/transformation/use-strict/undefined-this-root-declaration/actual.js diff --git a/test/fixtures/transformation/use-strict/undefined-this-root-declaration/expected.js b/test/fixtures/transformation/use-strict/undefined-this-root-declaration/expected.js new file mode 100644 index 0000000000..e9be05fae1 --- /dev/null +++ b/test/fixtures/transformation/use-strict/undefined-this-root-declaration/expected.js @@ -0,0 +1,3 @@ +"use strict"; + +var self = undefined; \ No newline at end of file diff --git a/test/fixtures/transformation/use-strict/illegal-this-root-reference/actual.js b/test/fixtures/transformation/use-strict/undefined-this-root-reference/actual.js similarity index 100% rename from test/fixtures/transformation/use-strict/illegal-this-root-reference/actual.js rename to test/fixtures/transformation/use-strict/undefined-this-root-reference/actual.js diff --git a/test/fixtures/transformation/use-strict/undefined-this-root-reference/expected.js b/test/fixtures/transformation/use-strict/undefined-this-root-reference/expected.js new file mode 100644 index 0000000000..34c5918e4c --- /dev/null +++ b/test/fixtures/transformation/use-strict/undefined-this-root-reference/expected.js @@ -0,0 +1,3 @@ +"use strict"; + +undefined; \ No newline at end of file