From cb54c11d84ce3aba5d851eea74e8db26960bbde9 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Sun, 4 Jan 2015 07:39:11 +1100 Subject: [PATCH 01/14] add esnext tests --- test/_helper.js | 13 ++++- .../arguments-refers-to-parent-function.js | 57 +++++++++++++++++++ ...es-not-bind-this-from-standard-function.js | 5 ++ .../empty-arrow-function.js | 2 + .../handles-nested-context-bindings.js | 12 ++++ ...rens-for-low-precedence-expression-body.js | 2 + .../object-literal-needs-parens.js | 2 + .../only-lexical-this-not-dynamic-this.js | 7 +++ .../passed-to-function.js | 2 + .../single-param-does-not-need-parens.js | 2 + .../esnext-es6-classes/anonymous-class.js | 29 ++++++++++ .../esnext-es6-classes/call-super-function.js | 21 +++++++ .../esnext-es6-classes/class-expressions.js | 9 +++ .../esnext-es6-classes/class-extend.js | 15 +++++ .../class-with-constructor.js | 14 +++++ .../class-with-method-declaration.js | 10 ++++ .../esnext-es6-classes/empty-named-class.js | 5 ++ .../esnext-es6-classes/enumerable.js | 20 +++++++ .../explicit-super-in-constructor.js | 15 +++++ .../esnext-es6-classes/extends-null.js | 4 ++ .../esnext-es6-classes/getter-setter-super.js | 15 +++++ .../esnext-es6-classes/getter-setter.js | 28 +++++++++ .../esnext-es6-classes/implicit-superclass.js | 9 +++ .../method-declaration-with-arguments.js | 7 +++ .../methods-are-writable.js | 12 ++++ .../methods-with-rest-params.js | 28 +++++++++ .../esnext-es6-classes/static-getter.js | 12 ++++ .../esnext-es6-classes/static-method.js | 30 ++++++++++ .../esnext-es6-classes/static-setter.js | 7 +++ .../esnext-es6-classes/strict-mode.js | 23 ++++++++ .../esnext-es6-classes/super-change-proto.js | 20 +++++++ .../accessor.js | 8 +++ .../esnext-es6-computed-properties/method.js | 3 + .../esnext-es6-computed-properties/nested.js | 4 ++ .../esnext-es6-computed-properties/simple.js | 3 + .../esnext-es6-default-parameters/arity.js | 3 + .../arrow-function.js | 8 +++ .../null-vs-undefined.js | 5 ++ .../esnext-es6-default-parameters/scope.js | 11 ++++ .../simple-function.js | 4 ++ .../method-arguments.js | 7 +++ .../method-context.js | 9 +++ .../method-has-name.js | 7 +++ .../method-is-not-in-scope-inside.js | 9 +++ .../method-to-string.js | 10 ++++ .../esnext-es6-object-concise/method.js | 7 +++ .../esnext-es6-rest-parameters/arrow-fn.js | 8 +++ .../esnext-es6-rest-parameters/declaration.js | 8 +++ .../esnext-es6-rest-parameters/rest.js | 8 +++ .../esnext-es6-spread/arguments-as-array.js | 6 ++ .../esnext-es6-spread/array-literal.js | 3 + .../call-with-array-literal.js | 5 ++ .../inside-function-expression.js | 10 ++++ .../esnext-es6-spread/iterator.js | 19 +++++++ .../esnext-es6-spread/new-object.js | 11 ++++ .../esnext-es6-spread/preserve-context.js | 35 ++++++++++++ .../esnext-es6-spread/simple-function-call.js | 6 ++ .../esnext-es6-templates/multi-line.js | 4 ++ .../nested-interpolation.js | 4 ++ .../esnext-es6-templates/no-interpolation.js | 2 + .../raw-tagged-template-expression.js | 6 ++ .../simple-interpolation.js | 2 + .../tagged-template-expression.js | 26 +++++++++ 63 files changed, 695 insertions(+), 3 deletions(-) create mode 100644 test/fixtures/transformation/esnext-es6-arrow-functions/arguments-refers-to-parent-function.js create mode 100644 test/fixtures/transformation/esnext-es6-arrow-functions/does-not-bind-this-from-standard-function.js create mode 100644 test/fixtures/transformation/esnext-es6-arrow-functions/empty-arrow-function.js create mode 100644 test/fixtures/transformation/esnext-es6-arrow-functions/handles-nested-context-bindings.js create mode 100644 test/fixtures/transformation/esnext-es6-arrow-functions/no-parens-for-low-precedence-expression-body.js create mode 100644 test/fixtures/transformation/esnext-es6-arrow-functions/object-literal-needs-parens.js create mode 100644 test/fixtures/transformation/esnext-es6-arrow-functions/only-lexical-this-not-dynamic-this.js create mode 100644 test/fixtures/transformation/esnext-es6-arrow-functions/passed-to-function.js create mode 100644 test/fixtures/transformation/esnext-es6-arrow-functions/single-param-does-not-need-parens.js create mode 100644 test/fixtures/transformation/esnext-es6-classes/anonymous-class.js create mode 100644 test/fixtures/transformation/esnext-es6-classes/call-super-function.js create mode 100644 test/fixtures/transformation/esnext-es6-classes/class-expressions.js create mode 100644 test/fixtures/transformation/esnext-es6-classes/class-extend.js create mode 100644 test/fixtures/transformation/esnext-es6-classes/class-with-constructor.js create mode 100644 test/fixtures/transformation/esnext-es6-classes/class-with-method-declaration.js create mode 100644 test/fixtures/transformation/esnext-es6-classes/empty-named-class.js create mode 100644 test/fixtures/transformation/esnext-es6-classes/enumerable.js create mode 100644 test/fixtures/transformation/esnext-es6-classes/explicit-super-in-constructor.js create mode 100644 test/fixtures/transformation/esnext-es6-classes/extends-null.js create mode 100644 test/fixtures/transformation/esnext-es6-classes/getter-setter-super.js create mode 100644 test/fixtures/transformation/esnext-es6-classes/getter-setter.js create mode 100644 test/fixtures/transformation/esnext-es6-classes/implicit-superclass.js create mode 100644 test/fixtures/transformation/esnext-es6-classes/method-declaration-with-arguments.js create mode 100644 test/fixtures/transformation/esnext-es6-classes/methods-are-writable.js create mode 100644 test/fixtures/transformation/esnext-es6-classes/methods-with-rest-params.js create mode 100644 test/fixtures/transformation/esnext-es6-classes/static-getter.js create mode 100644 test/fixtures/transformation/esnext-es6-classes/static-method.js create mode 100644 test/fixtures/transformation/esnext-es6-classes/static-setter.js create mode 100644 test/fixtures/transformation/esnext-es6-classes/strict-mode.js create mode 100644 test/fixtures/transformation/esnext-es6-classes/super-change-proto.js create mode 100644 test/fixtures/transformation/esnext-es6-computed-properties/accessor.js create mode 100644 test/fixtures/transformation/esnext-es6-computed-properties/method.js create mode 100644 test/fixtures/transformation/esnext-es6-computed-properties/nested.js create mode 100644 test/fixtures/transformation/esnext-es6-computed-properties/simple.js create mode 100644 test/fixtures/transformation/esnext-es6-default-parameters/arity.js create mode 100644 test/fixtures/transformation/esnext-es6-default-parameters/arrow-function.js create mode 100644 test/fixtures/transformation/esnext-es6-default-parameters/null-vs-undefined.js create mode 100644 test/fixtures/transformation/esnext-es6-default-parameters/scope.js create mode 100644 test/fixtures/transformation/esnext-es6-default-parameters/simple-function.js create mode 100644 test/fixtures/transformation/esnext-es6-object-concise/method-arguments.js create mode 100644 test/fixtures/transformation/esnext-es6-object-concise/method-context.js create mode 100644 test/fixtures/transformation/esnext-es6-object-concise/method-has-name.js create mode 100644 test/fixtures/transformation/esnext-es6-object-concise/method-is-not-in-scope-inside.js create mode 100644 test/fixtures/transformation/esnext-es6-object-concise/method-to-string.js create mode 100644 test/fixtures/transformation/esnext-es6-object-concise/method.js create mode 100644 test/fixtures/transformation/esnext-es6-rest-parameters/arrow-fn.js create mode 100644 test/fixtures/transformation/esnext-es6-rest-parameters/declaration.js create mode 100644 test/fixtures/transformation/esnext-es6-rest-parameters/rest.js create mode 100644 test/fixtures/transformation/esnext-es6-spread/arguments-as-array.js create mode 100644 test/fixtures/transformation/esnext-es6-spread/array-literal.js create mode 100644 test/fixtures/transformation/esnext-es6-spread/call-with-array-literal.js create mode 100644 test/fixtures/transformation/esnext-es6-spread/inside-function-expression.js create mode 100644 test/fixtures/transformation/esnext-es6-spread/iterator.js create mode 100644 test/fixtures/transformation/esnext-es6-spread/new-object.js create mode 100644 test/fixtures/transformation/esnext-es6-spread/preserve-context.js create mode 100644 test/fixtures/transformation/esnext-es6-spread/simple-function-call.js create mode 100644 test/fixtures/transformation/esnext-es6-templates/multi-line.js create mode 100644 test/fixtures/transformation/esnext-es6-templates/nested-interpolation.js create mode 100644 test/fixtures/transformation/esnext-es6-templates/no-interpolation.js create mode 100644 test/fixtures/transformation/esnext-es6-templates/raw-tagged-template-expression.js create mode 100644 test/fixtures/transformation/esnext-es6-templates/simple-interpolation.js create mode 100644 test/fixtures/transformation/esnext-es6-templates/tagged-template-expression.js diff --git a/test/_helper.js b/test/_helper.js index a988f30d73..8273a11443 100644 --- a/test/_helper.js +++ b/test/_helper.js @@ -1,5 +1,6 @@ -var fs = require("fs"); -var _ = require("lodash"); +var path = require("path"); +var fs = require("fs"); +var _ = require("lodash"); var humanise = function (val) { return val.replace(/-/g, " "); @@ -37,7 +38,6 @@ exports.get = function (entryName) { _.each(fs.readdirSync(suite.filename), function (taskName) { var taskDir = suite.filename + "/" + taskName; - if (fs.statSync(taskDir).isFile()) return; var actualLocAlias = suiteName + "/" + taskName + "/actual.js"; var expectLocAlias = suiteName + "/" + taskName + "/expected.js"; @@ -47,6 +47,13 @@ exports.get = function (entryName) { var expectLoc = taskDir + "/expected.js"; var execLoc = taskDir + "/exec.js"; + if (fs.statSync(taskDir).isFile()) { + var ext = path.extname(taskDir); + if (ext === ".json") return; + + execLoc = taskDir; + } + var taskOpts = _.merge({ filenameRelative: expectLocAlias, sourceFileName: actualLocAlias, diff --git a/test/fixtures/transformation/esnext-es6-arrow-functions/arguments-refers-to-parent-function.js b/test/fixtures/transformation/esnext-es6-arrow-functions/arguments-refers-to-parent-function.js new file mode 100644 index 0000000000..d299fb5379 --- /dev/null +++ b/test/fixtures/transformation/esnext-es6-arrow-functions/arguments-refers-to-parent-function.js @@ -0,0 +1,57 @@ +function makeMultiplier() { + // `arguments` should refer to `makeMultiplier`'s arguments. + return (n) => [].slice.call(arguments).reduce((a, b) => a * b) * n; +} + +function toArray() { + // Intentionally nest arrow functions to ensure `arguments` is put inside + // `toArray`'s scope. + return (() => (arguments, (() => [].slice.call(arguments)).call())).call(); +} + +function returnDotArguments(object) { + // Ensure `arguments` is not treated as a reference to the magic value. + return (() => object.arguments).call(); +} + +function returnArgumentsObject() { + // Ensure `arguments` is not treated as a reference to the magic value. + return (() => ({arguments: 1})).call(); +} + +function makeArgumentsReturner() { + return (() => function() { + return [].slice.call(arguments); + }).call(); +} + +// i.e. 2 * 3 * 4 == 24, not 16 (4 * 4) +assert.equal( + makeMultiplier(2, 3)(4), + 24, + 'ensure `arguments` is hoisted out to the first non-arrow scope' +); + +assert.deepEqual( + toArray(1, 2, 3), + [1, 2, 3], + 'ensure `arguments` is hoisted out to the first non-arrow scope' +); + +assert.equal( + returnDotArguments({arguments: 1}), + 1, + 'member accesses with `arguments` property should not be replaced' +); + +assert.deepEqual( + returnArgumentsObject(), + {arguments: 1}, + 'object property keys named `arguments` should not be replaced' +); + +assert.deepEqual( + makeArgumentsReturner()(1, 2, 3), + [1, 2, 3], + 'arguments should not be hoisted from inside non-arrow functions' +); diff --git a/test/fixtures/transformation/esnext-es6-arrow-functions/does-not-bind-this-from-standard-function.js b/test/fixtures/transformation/esnext-es6-arrow-functions/does-not-bind-this-from-standard-function.js new file mode 100644 index 0000000000..c2eeddcc3e --- /dev/null +++ b/test/fixtures/transformation/esnext-es6-arrow-functions/does-not-bind-this-from-standard-function.js @@ -0,0 +1,5 @@ +var dynamicThisGetter = () => function(){ return this; }; +assert.equal( + normalize('('+dynamicThisGetter.toString()+')'), + normalize('(function(){ return function(){ return this; }; })') +); diff --git a/test/fixtures/transformation/esnext-es6-arrow-functions/empty-arrow-function.js b/test/fixtures/transformation/esnext-es6-arrow-functions/empty-arrow-function.js new file mode 100644 index 0000000000..0b95435853 --- /dev/null +++ b/test/fixtures/transformation/esnext-es6-arrow-functions/empty-arrow-function.js @@ -0,0 +1,2 @@ +var empty = () => {}; +assert.equal(empty(), undefined); diff --git a/test/fixtures/transformation/esnext-es6-arrow-functions/handles-nested-context-bindings.js b/test/fixtures/transformation/esnext-es6-arrow-functions/handles-nested-context-bindings.js new file mode 100644 index 0000000000..03041f0297 --- /dev/null +++ b/test/fixtures/transformation/esnext-es6-arrow-functions/handles-nested-context-bindings.js @@ -0,0 +1,12 @@ +var obj = { + method: function() { + return () => (this, () => this); + }, + + method2: function() { + return () => () => this; + } +}; + +assert.strictEqual(obj.method()()(), obj); +assert.strictEqual(obj.method2()()(), obj); diff --git a/test/fixtures/transformation/esnext-es6-arrow-functions/no-parens-for-low-precedence-expression-body.js b/test/fixtures/transformation/esnext-es6-arrow-functions/no-parens-for-low-precedence-expression-body.js new file mode 100644 index 0000000000..66fad996e5 --- /dev/null +++ b/test/fixtures/transformation/esnext-es6-arrow-functions/no-parens-for-low-precedence-expression-body.js @@ -0,0 +1,2 @@ +var square = x => x * x; +assert.equal(square(4), 16); diff --git a/test/fixtures/transformation/esnext-es6-arrow-functions/object-literal-needs-parens.js b/test/fixtures/transformation/esnext-es6-arrow-functions/object-literal-needs-parens.js new file mode 100644 index 0000000000..3ec553b180 --- /dev/null +++ b/test/fixtures/transformation/esnext-es6-arrow-functions/object-literal-needs-parens.js @@ -0,0 +1,2 @@ +var keyMaker = val => ({ key: val }); +assert.deepEqual(keyMaker(9), { key: 9 }); diff --git a/test/fixtures/transformation/esnext-es6-arrow-functions/only-lexical-this-not-dynamic-this.js b/test/fixtures/transformation/esnext-es6-arrow-functions/only-lexical-this-not-dynamic-this.js new file mode 100644 index 0000000000..68f68c14dc --- /dev/null +++ b/test/fixtures/transformation/esnext-es6-arrow-functions/only-lexical-this-not-dynamic-this.js @@ -0,0 +1,7 @@ +var obj = { + method: function() { + return () => this; + } +}; + +assert.strictEqual(obj.method()(), obj); diff --git a/test/fixtures/transformation/esnext-es6-arrow-functions/passed-to-function.js b/test/fixtures/transformation/esnext-es6-arrow-functions/passed-to-function.js new file mode 100644 index 0000000000..75fbefbacd --- /dev/null +++ b/test/fixtures/transformation/esnext-es6-arrow-functions/passed-to-function.js @@ -0,0 +1,2 @@ +var odds = [0, 2, 4].map(v => v + 1); +assert.deepEqual(odds, [1, 3, 5]); diff --git a/test/fixtures/transformation/esnext-es6-arrow-functions/single-param-does-not-need-parens.js b/test/fixtures/transformation/esnext-es6-arrow-functions/single-param-does-not-need-parens.js new file mode 100644 index 0000000000..c2b56e7bbc --- /dev/null +++ b/test/fixtures/transformation/esnext-es6-arrow-functions/single-param-does-not-need-parens.js @@ -0,0 +1,2 @@ +var identity = x => x; +assert.equal(identity(1), 1); diff --git a/test/fixtures/transformation/esnext-es6-classes/anonymous-class.js b/test/fixtures/transformation/esnext-es6-classes/anonymous-class.js new file mode 100644 index 0000000000..231ba49b9e --- /dev/null +++ b/test/fixtures/transformation/esnext-es6-classes/anonymous-class.js @@ -0,0 +1,29 @@ +var Animal = class { + sayHi() { + return 'Hi, I am a '+this.type()+'.'; + } + + static getName() { + return 'Animal'; + } +}; + +var Dog = class extends Animal { + type() { return 'dog'; } + + sayHi() { + return super() + ' WOOF!'; + } + + static getName() { + return super() + '/Dog'; + } +}; + +assert.equal(new Dog().sayHi(), 'Hi, I am a dog. WOOF!'); +assert.equal(Dog.getName(), 'Animal/Dog'); + +var count = 0; +var Cat = class extends (function(){ count++; return Animal; })() {}; + +assert.equal(count, 1); diff --git a/test/fixtures/transformation/esnext-es6-classes/call-super-function.js b/test/fixtures/transformation/esnext-es6-classes/call-super-function.js new file mode 100644 index 0000000000..5c7efe0dc6 --- /dev/null +++ b/test/fixtures/transformation/esnext-es6-classes/call-super-function.js @@ -0,0 +1,21 @@ +class Animal { + sayHi() { + return 'I am an animal.' + } + + sayOther() { + return 'WAT?!'; + } +} + +class Horse extends Animal { + sayHi() { + return super.sayOther(); + } + + sayOther() { + return 'I see dead objects.'; + } +} + +assert.equal(new Horse().sayHi(), 'WAT?!'); diff --git a/test/fixtures/transformation/esnext-es6-classes/class-expressions.js b/test/fixtures/transformation/esnext-es6-classes/class-expressions.js new file mode 100644 index 0000000000..1c2bb96a80 --- /dev/null +++ b/test/fixtures/transformation/esnext-es6-classes/class-expressions.js @@ -0,0 +1,9 @@ +var Person = (class Person {}); +assert.equal(typeof Person, 'function'); + +assert.equal( + (function(){ return (class Person {}); })().name, + 'Person' +); + +assert.equal(typeof (class {}), 'function'); diff --git a/test/fixtures/transformation/esnext-es6-classes/class-extend.js b/test/fixtures/transformation/esnext-es6-classes/class-extend.js new file mode 100644 index 0000000000..56035dd0b6 --- /dev/null +++ b/test/fixtures/transformation/esnext-es6-classes/class-extend.js @@ -0,0 +1,15 @@ +class Animal { + sayHi() { + return 'Hi, I am a '+this.type()+'.'; + } +} + +class Dog extends Animal { + type() { return 'dog'; } + + sayHi() { + return super() + ' WOOF!'; + } +} + +assert.equal(new Dog().sayHi(), 'Hi, I am a dog. WOOF!'); diff --git a/test/fixtures/transformation/esnext-es6-classes/class-with-constructor.js b/test/fixtures/transformation/esnext-es6-classes/class-with-constructor.js new file mode 100644 index 0000000000..4dcf3296f0 --- /dev/null +++ b/test/fixtures/transformation/esnext-es6-classes/class-with-constructor.js @@ -0,0 +1,14 @@ +class Multiplier { + constructor(n=1) { + this.n = n; + } + + multiply(n=1) { + return n * this.n; + } +} + +assert.equal(new Multiplier().n, 1); +assert.equal(new Multiplier(6).n, 6); +assert.equal(new Multiplier().multiply(), 1); +assert.equal(new Multiplier(2).multiply(3), 6); diff --git a/test/fixtures/transformation/esnext-es6-classes/class-with-method-declaration.js b/test/fixtures/transformation/esnext-es6-classes/class-with-method-declaration.js new file mode 100644 index 0000000000..f8d9d7a207 --- /dev/null +++ b/test/fixtures/transformation/esnext-es6-classes/class-with-method-declaration.js @@ -0,0 +1,10 @@ +class Person { + getName() { + return this.firstName + ' ' + this.lastName; + } +} + +var me = new Person(); +me.firstName = 'Brian'; +me.lastName = 'Donovan'; +assert.equal(me.getName(), 'Brian Donovan'); diff --git a/test/fixtures/transformation/esnext-es6-classes/empty-named-class.js b/test/fixtures/transformation/esnext-es6-classes/empty-named-class.js new file mode 100644 index 0000000000..602a6702d3 --- /dev/null +++ b/test/fixtures/transformation/esnext-es6-classes/empty-named-class.js @@ -0,0 +1,5 @@ +class Foo { +} + +assert.equal(new Foo().constructor, Foo, 'Foo instances should have Foo as constructor'); +assert.ok(new Foo() instanceof Foo, 'Foo instances should be `instanceof` Foo'); diff --git a/test/fixtures/transformation/esnext-es6-classes/enumerable.js b/test/fixtures/transformation/esnext-es6-classes/enumerable.js new file mode 100644 index 0000000000..fe5c02d113 --- /dev/null +++ b/test/fixtures/transformation/esnext-es6-classes/enumerable.js @@ -0,0 +1,20 @@ +class Point { + constructor(x, y) { + this.x = x; + this.y = y; + } + + toString() { + return '(' + this.x + ', ' + this.y + ')'; + } +} + +var point = new Point(1, 2); +var keys = []; + +for (var key in point) { + keys.push(key); +} + +assert.equal(point.toString(), '(1, 2)'); +assert.deepEqual(keys.sort(), ['x', 'y']); diff --git a/test/fixtures/transformation/esnext-es6-classes/explicit-super-in-constructor.js b/test/fixtures/transformation/esnext-es6-classes/explicit-super-in-constructor.js new file mode 100644 index 0000000000..d30f21cba5 --- /dev/null +++ b/test/fixtures/transformation/esnext-es6-classes/explicit-super-in-constructor.js @@ -0,0 +1,15 @@ +class Point { + constructor(x, y) { + this.x = x; + this.y = y; + } +} + +class ZeroPoint extends Point { + constructor() { + super(0, 0); + } +} + +assert.equal(new ZeroPoint().x, 0); +assert.equal(new ZeroPoint().y, 0); diff --git a/test/fixtures/transformation/esnext-es6-classes/extends-null.js b/test/fixtures/transformation/esnext-es6-classes/extends-null.js new file mode 100644 index 0000000000..fa3821d8c7 --- /dev/null +++ b/test/fixtures/transformation/esnext-es6-classes/extends-null.js @@ -0,0 +1,4 @@ +class Obj extends null {} + +assert.strictEqual(Obj.toString, Function.toString); +assert.strictEqual(new Obj().toString, undefined); diff --git a/test/fixtures/transformation/esnext-es6-classes/getter-setter-super.js b/test/fixtures/transformation/esnext-es6-classes/getter-setter-super.js new file mode 100644 index 0000000000..98d7bc0eea --- /dev/null +++ b/test/fixtures/transformation/esnext-es6-classes/getter-setter-super.js @@ -0,0 +1,15 @@ +class Animal { + get sound() { + return 'I am a ' + this.type + '.'; + } +} + +class Cat extends Animal { + get type() { return 'cat'; } + + get sound() { + return super.sound + ' MEOW!'; + } +} + +assert.equal(new Cat().sound, 'I am a cat. MEOW!'); diff --git a/test/fixtures/transformation/esnext-es6-classes/getter-setter.js b/test/fixtures/transformation/esnext-es6-classes/getter-setter.js new file mode 100644 index 0000000000..8f9519f9ba --- /dev/null +++ b/test/fixtures/transformation/esnext-es6-classes/getter-setter.js @@ -0,0 +1,28 @@ +class Person { + constructor(firstName, lastName) { + this.firstName = firstName; + this.lastName = lastName; + } + + get name() { + return this.firstName + ' ' + this.lastName; + } + + set name(name) { + var parts = name.split(' '); + this.firstName = parts[0]; + this.lastName = parts[1]; + } +} + +var mazer = new Person('Mazer', 'Rackham'); +assert.equal(mazer.name, 'Mazer Rackham'); +mazer.name = 'Ender Wiggin'; +assert.equal(mazer.firstName, 'Ender'); +assert.equal(mazer.lastName, 'Wiggin'); + +var forLoopProperties = []; +for (var key in mazer) { + forLoopProperties.push(key); +} +assert.ok(forLoopProperties.indexOf('name') >= 0, 'getters/setters are enumerable'); diff --git a/test/fixtures/transformation/esnext-es6-classes/implicit-superclass.js b/test/fixtures/transformation/esnext-es6-classes/implicit-superclass.js new file mode 100644 index 0000000000..96755df101 --- /dev/null +++ b/test/fixtures/transformation/esnext-es6-classes/implicit-superclass.js @@ -0,0 +1,9 @@ +class Obj { + constructor() { + super(); + } +} + +assert.doesNotThrow(function() { + new Obj(); +}); diff --git a/test/fixtures/transformation/esnext-es6-classes/method-declaration-with-arguments.js b/test/fixtures/transformation/esnext-es6-classes/method-declaration-with-arguments.js new file mode 100644 index 0000000000..b70c56e68c --- /dev/null +++ b/test/fixtures/transformation/esnext-es6-classes/method-declaration-with-arguments.js @@ -0,0 +1,7 @@ +class Tripler { + triple(n) { + return n * 3; + } +} + +assert.equal(new Tripler().triple(2), 6); diff --git a/test/fixtures/transformation/esnext-es6-classes/methods-are-writable.js b/test/fixtures/transformation/esnext-es6-classes/methods-are-writable.js new file mode 100644 index 0000000000..19ffd5aa73 --- /dev/null +++ b/test/fixtures/transformation/esnext-es6-classes/methods-are-writable.js @@ -0,0 +1,12 @@ +var value; + +class Foo { + foo() { + value = 1; + } +} + +var foo = new Foo(); +foo.foo = function() { value = 2; }; +foo.foo(); +assert.equal(value, 2); diff --git a/test/fixtures/transformation/esnext-es6-classes/methods-with-rest-params.js b/test/fixtures/transformation/esnext-es6-classes/methods-with-rest-params.js new file mode 100644 index 0000000000..77b7bb0774 --- /dev/null +++ b/test/fixtures/transformation/esnext-es6-classes/methods-with-rest-params.js @@ -0,0 +1,28 @@ +class Joiner { + constructor(string) { + this.string = string; + } + + join(...items) { + return items.join(this.string); + } + + static join(string, ...items) { + var joiner = new this(string); + // TODO: use spread params here + return joiner.join.apply(joiner, items); + } +} + +class ArrayLike { + constructor(...items) { + items.forEach(function(item, i) { + this[i] = item; + }.bind(this)); + this.length = items.length; + } +} + +var joiner = new Joiner(' & '); +assert.equal(joiner.join(4, 5, 6), '4 & 5 & 6'); +assert.equal(new ArrayLike('a', 'b')[1], 'b'); diff --git a/test/fixtures/transformation/esnext-es6-classes/static-getter.js b/test/fixtures/transformation/esnext-es6-classes/static-getter.js new file mode 100644 index 0000000000..af9fe0afe6 --- /dev/null +++ b/test/fixtures/transformation/esnext-es6-classes/static-getter.js @@ -0,0 +1,12 @@ +class Point { + constructor(x, y) { + this.x = x; + this.y = y; + } + + static get ORIGIN() { + return new this(0, 0); + } +} + +assert.deepEqual(Point.ORIGIN, new Point(0, 0)); \ No newline at end of file diff --git a/test/fixtures/transformation/esnext-es6-classes/static-method.js b/test/fixtures/transformation/esnext-es6-classes/static-method.js new file mode 100644 index 0000000000..564fb13c5b --- /dev/null +++ b/test/fixtures/transformation/esnext-es6-classes/static-method.js @@ -0,0 +1,30 @@ +class Tripler { + static triple(n=1) { + return n * 3; + } + + static toString() { + return '3' + super() + '3'; + } +} + +class MegaTripler extends Tripler { + static triple(n=1) { + return super(n) * super(n); + } +} + +var tripler = new Tripler(); + +assert.equal(Tripler.triple(), 3); +assert.equal(Tripler.triple(2), 6); +assert.equal(tripler.triple, undefined); + +assert.equal(Tripler.toString(), '3' + Object.toString.call(Tripler) + '3'); + +var mega = new MegaTripler(); + +assert.equal(MegaTripler.triple(2), 36); +assert.equal(mega.triple, undefined); + +assert.equal(MegaTripler.toString(), '3' + Object.toString.call(MegaTripler) + '3'); diff --git a/test/fixtures/transformation/esnext-es6-classes/static-setter.js b/test/fixtures/transformation/esnext-es6-classes/static-setter.js new file mode 100644 index 0000000000..08fae30af5 --- /dev/null +++ b/test/fixtures/transformation/esnext-es6-classes/static-setter.js @@ -0,0 +1,7 @@ +class Person { + static set DB(value) { + assert.equal(value, 'mysql'); + } +} + +Person.DB = 'mysql'; diff --git a/test/fixtures/transformation/esnext-es6-classes/strict-mode.js b/test/fixtures/transformation/esnext-es6-classes/strict-mode.js new file mode 100644 index 0000000000..d3ece2608e --- /dev/null +++ b/test/fixtures/transformation/esnext-es6-classes/strict-mode.js @@ -0,0 +1,23 @@ +class StrictModeTest { + test() { + var implicitThisInsideClassBody = (function() { + return this; + })(); + assert.strictEqual( + implicitThisInsideClassBody, + undefined, + 'implicit `this` inside class body is undefined' + ); + } +} + +new StrictModeTest().test(); + +var implicitThisOutsideClass = (function() { + return this; +})(); +assert.notStrictEqual( + implicitThisOutsideClass, + undefined, + 'implicit `this` outside class body is not undefined' +); diff --git a/test/fixtures/transformation/esnext-es6-classes/super-change-proto.js b/test/fixtures/transformation/esnext-es6-classes/super-change-proto.js new file mode 100644 index 0000000000..d0012cfc0b --- /dev/null +++ b/test/fixtures/transformation/esnext-es6-classes/super-change-proto.js @@ -0,0 +1,20 @@ +var log = ''; + +class Base { + p() { log += '[Base]'; } +} + +class OtherBase { + p() { log += '[OtherBase]'; } +} +class Derived extends Base { + p() { + log += '[Derived]'; + super(); + Derived.prototype.__proto__ = OtherBase.prototype; + super(); + } +} + +new Derived().p(); +assert.equal(log, '[Derived][Base][OtherBase]'); diff --git a/test/fixtures/transformation/esnext-es6-computed-properties/accessor.js b/test/fixtures/transformation/esnext-es6-computed-properties/accessor.js new file mode 100644 index 0000000000..bedcb7785a --- /dev/null +++ b/test/fixtures/transformation/esnext-es6-computed-properties/accessor.js @@ -0,0 +1,8 @@ +var x = 'y'; + +var foo = { + get [x]() { return this._y; }, + set [x](v) { this._y = v; } +}; + +assert.equal((foo.y = 10, foo.y), 10); diff --git a/test/fixtures/transformation/esnext-es6-computed-properties/method.js b/test/fixtures/transformation/esnext-es6-computed-properties/method.js new file mode 100644 index 0000000000..e28e4d18d5 --- /dev/null +++ b/test/fixtures/transformation/esnext-es6-computed-properties/method.js @@ -0,0 +1,3 @@ +var x = 'y'; +assert.equal({[x]: function() { return 10; }}.y(), 10); +assert.equal({[x + 'y']() { return 10; }}.yy(), 10); diff --git a/test/fixtures/transformation/esnext-es6-computed-properties/nested.js b/test/fixtures/transformation/esnext-es6-computed-properties/nested.js new file mode 100644 index 0000000000..ea11b2c6f6 --- /dev/null +++ b/test/fixtures/transformation/esnext-es6-computed-properties/nested.js @@ -0,0 +1,4 @@ +var x = 'y'; +var foo = {[x]: 10, z: {[x]: 10}}; +assert.equal(foo.y + foo.z.y, 20); +assert.equal({[x]: {[x]: {[x]: 10}}}.y.y.y, 10); diff --git a/test/fixtures/transformation/esnext-es6-computed-properties/simple.js b/test/fixtures/transformation/esnext-es6-computed-properties/simple.js new file mode 100644 index 0000000000..21e56afe58 --- /dev/null +++ b/test/fixtures/transformation/esnext-es6-computed-properties/simple.js @@ -0,0 +1,3 @@ +var x = 'y'; +assert.equal({[x]: 10}.y, 10); +assert.equal({[x + 'y']: 10}.yy, 10); diff --git a/test/fixtures/transformation/esnext-es6-default-parameters/arity.js b/test/fixtures/transformation/esnext-es6-default-parameters/arity.js new file mode 100644 index 0000000000..030f3e08ea --- /dev/null +++ b/test/fixtures/transformation/esnext-es6-default-parameters/arity.js @@ -0,0 +1,3 @@ +assert.equal((function(a){}).length, 1); +assert.equal((function(a=5){}).length, 0); +assert.equal((function(a, b, c=5){}).length, 2); diff --git a/test/fixtures/transformation/esnext-es6-default-parameters/arrow-function.js b/test/fixtures/transformation/esnext-es6-default-parameters/arrow-function.js new file mode 100644 index 0000000000..66c0068d94 --- /dev/null +++ b/test/fixtures/transformation/esnext-es6-default-parameters/arrow-function.js @@ -0,0 +1,8 @@ +function makeMultiplier(x=1) { + return (y=1) => x * y; +} + +assert.equal(makeMultiplier()(), 1); +assert.equal(makeMultiplier(2)(3), 6); +assert.deepEqual([1, 2, 3].map(makeMultiplier(2)), [2, 4, 6]); +assert.deepEqual([undefined, null, 0].map(makeMultiplier(2)), [2, 0, 0]); diff --git a/test/fixtures/transformation/esnext-es6-default-parameters/null-vs-undefined.js b/test/fixtures/transformation/esnext-es6-default-parameters/null-vs-undefined.js new file mode 100644 index 0000000000..b028ba3e09 --- /dev/null +++ b/test/fixtures/transformation/esnext-es6-default-parameters/null-vs-undefined.js @@ -0,0 +1,5 @@ +function foo(x=5, y=6) { + return [x, y]; +} + +assert.deepEqual(foo(undefined, null), [5, null]); diff --git a/test/fixtures/transformation/esnext-es6-default-parameters/scope.js b/test/fixtures/transformation/esnext-es6-default-parameters/scope.js new file mode 100644 index 0000000000..54848cd8f2 --- /dev/null +++ b/test/fixtures/transformation/esnext-es6-default-parameters/scope.js @@ -0,0 +1,11 @@ +function call(fn, context=this) { + return fn.call(context); +} + +var context = {a: 99}; + +// use the default parameter +assert.strictEqual(call.call(context, function(){ return this.a; }), 99); + +// explicitly provide the default parameter value +assert.strictEqual(call(function(){ return this.a; }, context), 99); diff --git a/test/fixtures/transformation/esnext-es6-default-parameters/simple-function.js b/test/fixtures/transformation/esnext-es6-default-parameters/simple-function.js new file mode 100644 index 0000000000..d7bf1bfa1c --- /dev/null +++ b/test/fixtures/transformation/esnext-es6-default-parameters/simple-function.js @@ -0,0 +1,4 @@ +function foo(x=5) { + return x; +} +assert.equal(foo(), 5); diff --git a/test/fixtures/transformation/esnext-es6-object-concise/method-arguments.js b/test/fixtures/transformation/esnext-es6-object-concise/method-arguments.js new file mode 100644 index 0000000000..392586fc9b --- /dev/null +++ b/test/fixtures/transformation/esnext-es6-object-concise/method-arguments.js @@ -0,0 +1,7 @@ +var a = { + echo(c) { + return c; + } +}; + +assert.strictEqual(a.echo(1), 1); diff --git a/test/fixtures/transformation/esnext-es6-object-concise/method-context.js b/test/fixtures/transformation/esnext-es6-object-concise/method-context.js new file mode 100644 index 0000000000..53c4bf3bc7 --- /dev/null +++ b/test/fixtures/transformation/esnext-es6-object-concise/method-context.js @@ -0,0 +1,9 @@ +var a = { + b() { + return this; + } +}; + +var context = {}; +assert.strictEqual(a.b(), a); +assert.strictEqual(a.b.call(context), context); \ No newline at end of file diff --git a/test/fixtures/transformation/esnext-es6-object-concise/method-has-name.js b/test/fixtures/transformation/esnext-es6-object-concise/method-has-name.js new file mode 100644 index 0000000000..320ec33b54 --- /dev/null +++ b/test/fixtures/transformation/esnext-es6-object-concise/method-has-name.js @@ -0,0 +1,7 @@ +var a = { + b() { + return 'c'; + } +}; + +assert.equal(a.b.name, 'b'); diff --git a/test/fixtures/transformation/esnext-es6-object-concise/method-is-not-in-scope-inside.js b/test/fixtures/transformation/esnext-es6-object-concise/method-is-not-in-scope-inside.js new file mode 100644 index 0000000000..4f58980df0 --- /dev/null +++ b/test/fixtures/transformation/esnext-es6-object-concise/method-is-not-in-scope-inside.js @@ -0,0 +1,9 @@ +var b = 1; + +var a = { + b() { + return b; + } +}; + +assert.equal(a.b(), 1); diff --git a/test/fixtures/transformation/esnext-es6-object-concise/method-to-string.js b/test/fixtures/transformation/esnext-es6-object-concise/method-to-string.js new file mode 100644 index 0000000000..ba3f86cb78 --- /dev/null +++ b/test/fixtures/transformation/esnext-es6-object-concise/method-to-string.js @@ -0,0 +1,10 @@ +var a = { + b() { + return b; + } +}; + +assert.ok( + /return b/.test(a.b.toString()), + 'toString contains body' +); \ No newline at end of file diff --git a/test/fixtures/transformation/esnext-es6-object-concise/method.js b/test/fixtures/transformation/esnext-es6-object-concise/method.js new file mode 100644 index 0000000000..1707a7aebb --- /dev/null +++ b/test/fixtures/transformation/esnext-es6-object-concise/method.js @@ -0,0 +1,7 @@ +var a = { + b() { + return 'c'; + } +}; + +assert.equal(a.b(), 'c'); diff --git a/test/fixtures/transformation/esnext-es6-rest-parameters/arrow-fn.js b/test/fixtures/transformation/esnext-es6-rest-parameters/arrow-fn.js new file mode 100644 index 0000000000..34c96f5ecb --- /dev/null +++ b/test/fixtures/transformation/esnext-es6-rest-parameters/arrow-fn.js @@ -0,0 +1,8 @@ +/* jshint esnext: true */ +/* global expect */ + +var join = (joinStr, ...items) => { + return items.join(joinStr); +}; + +expect(join(' ', 'a', 'b', 'c')).to.equal('a b c'); diff --git a/test/fixtures/transformation/esnext-es6-rest-parameters/declaration.js b/test/fixtures/transformation/esnext-es6-rest-parameters/declaration.js new file mode 100644 index 0000000000..1cc45ac46f --- /dev/null +++ b/test/fixtures/transformation/esnext-es6-rest-parameters/declaration.js @@ -0,0 +1,8 @@ +/* jshint esnext: true */ +/* global expect */ + +function join(joinStr, ...items) { + return items.join(joinStr); +} + +expect(join(' ', 'a', 'b', 'c')).to.equal('a b c'); diff --git a/test/fixtures/transformation/esnext-es6-rest-parameters/rest.js b/test/fixtures/transformation/esnext-es6-rest-parameters/rest.js new file mode 100644 index 0000000000..9d0e63e85d --- /dev/null +++ b/test/fixtures/transformation/esnext-es6-rest-parameters/rest.js @@ -0,0 +1,8 @@ +/* jshint esnext: true */ +/* global expect */ + +var join = function(joinStr, ...items) { + return items.join(joinStr); +}; + +expect(join(' ', 'a', 'b', 'c')).to.equal('a b c'); diff --git a/test/fixtures/transformation/esnext-es6-spread/arguments-as-array.js b/test/fixtures/transformation/esnext-es6-spread/arguments-as-array.js new file mode 100644 index 0000000000..d0957e35b4 --- /dev/null +++ b/test/fixtures/transformation/esnext-es6-spread/arguments-as-array.js @@ -0,0 +1,6 @@ +function arrayOf() { + return [...arguments]; +} + +assert.equal(Object.prototype.toString.call(arrayOf()), '[object Array]'); +assert.deepEqual(arrayOf(1, 2, 3), [1, 2, 3]); diff --git a/test/fixtures/transformation/esnext-es6-spread/array-literal.js b/test/fixtures/transformation/esnext-es6-spread/array-literal.js new file mode 100644 index 0000000000..3c1bea826f --- /dev/null +++ b/test/fixtures/transformation/esnext-es6-spread/array-literal.js @@ -0,0 +1,3 @@ +var names = ['Brian', 'Madeline']; +assert.deepEqual(['Thomas', ...names], ['Thomas', 'Brian', 'Madeline']); +assert.deepEqual([1, 2, ...[3, 4, 5]], [1, 2, 3, 4, 5]); diff --git a/test/fixtures/transformation/esnext-es6-spread/call-with-array-literal.js b/test/fixtures/transformation/esnext-es6-spread/call-with-array-literal.js new file mode 100644 index 0000000000..19cffabc6d --- /dev/null +++ b/test/fixtures/transformation/esnext-es6-spread/call-with-array-literal.js @@ -0,0 +1,5 @@ +function sum(...numbers) { + return numbers.reduce(function(sum, n) { return n + sum; }, 0); +} + +assert.equal(sum(4, 5, ...[10, 20, 30]), 69); diff --git a/test/fixtures/transformation/esnext-es6-spread/inside-function-expression.js b/test/fixtures/transformation/esnext-es6-spread/inside-function-expression.js new file mode 100644 index 0000000000..c2c06da399 --- /dev/null +++ b/test/fixtures/transformation/esnext-es6-spread/inside-function-expression.js @@ -0,0 +1,10 @@ +var object = { + list: [], + + append: function(...items) { + this.list.push(...items); + } +}; + +object.append(1, 2, ...[3, 4]); +assert.deepEqual(object.list, [1, 2, 3, 4]); diff --git a/test/fixtures/transformation/esnext-es6-spread/iterator.js b/test/fixtures/transformation/esnext-es6-spread/iterator.js new file mode 100644 index 0000000000..438e7564de --- /dev/null +++ b/test/fixtures/transformation/esnext-es6-spread/iterator.js @@ -0,0 +1,19 @@ +function Symbol() {} +Symbol.iterator = '@@iterator'; + +var obj = { + '@@iterator': function() { + var ttl = 3; + return { + next: function() { + if (ttl === 0) { + return { done: true, value: null }; + } else { + return { done: false, value: ttl-- }; + } + } + }; + } +}; + +assert.deepEqual([3, 2, 1], [...obj]); diff --git a/test/fixtures/transformation/esnext-es6-spread/new-object.js b/test/fixtures/transformation/esnext-es6-spread/new-object.js new file mode 100644 index 0000000000..6e4af74279 --- /dev/null +++ b/test/fixtures/transformation/esnext-es6-spread/new-object.js @@ -0,0 +1,11 @@ +var callCount = 0; +function getArray() { + callCount++; + return Array; +} + +assert.deepEqual([1, 2, 3], new Array(...[1, 2, 3])); + +// Ensure the expression of the function being initialized is not copied. +assert.deepEqual([1, 2, 3], new (getArray())(...[1, 2, 3])); +assert.equal(callCount, 1); diff --git a/test/fixtures/transformation/esnext-es6-spread/preserve-context.js b/test/fixtures/transformation/esnext-es6-spread/preserve-context.js new file mode 100644 index 0000000000..e63f88e788 --- /dev/null +++ b/test/fixtures/transformation/esnext-es6-spread/preserve-context.js @@ -0,0 +1,35 @@ +var MATH = { + sum: function(...numbers) { + return numbers.reduce(this.add, 0); + }, + + add: function(a, b) { + return a + b; + } +}; + +assert.equal(MATH.sum(1, ...[2, 3]), 6); + +// Ensure that the below does not expand to this: +// +// obj.getSelf().call.apply(obj.getSelf(), []); +// + +var ops = []; +var obj = { + getSelf: function() { + ops.push('getSelf'); + return this; + }, + + doCall: function() { + ops.push('doCall', this); + } +}; + +obj.getSelf().doCall(...[]); +assert.deepEqual(ops, ['getSelf', 'doCall', obj]); + +ops = []; +obj['getSelf']().doCall(...[]); +assert.deepEqual(ops, ['getSelf', 'doCall', obj]); diff --git a/test/fixtures/transformation/esnext-es6-spread/simple-function-call.js b/test/fixtures/transformation/esnext-es6-spread/simple-function-call.js new file mode 100644 index 0000000000..106bfa55be --- /dev/null +++ b/test/fixtures/transformation/esnext-es6-spread/simple-function-call.js @@ -0,0 +1,6 @@ +function sum(...numbers) { + return numbers.reduce(function(sum, n) { return n + sum; }, 0); +} + +var numbers = [1, 2, 3]; +assert.equal(sum(...numbers), 6); diff --git a/test/fixtures/transformation/esnext-es6-templates/multi-line.js b/test/fixtures/transformation/esnext-es6-templates/multi-line.js new file mode 100644 index 0000000000..6d1be1c2bc --- /dev/null +++ b/test/fixtures/transformation/esnext-es6-templates/multi-line.js @@ -0,0 +1,4 @@ +var s = `a + b + c`; +assert.equal(s, 'a\n b\n c'); diff --git a/test/fixtures/transformation/esnext-es6-templates/nested-interpolation.js b/test/fixtures/transformation/esnext-es6-templates/nested-interpolation.js new file mode 100644 index 0000000000..83083e9fd0 --- /dev/null +++ b/test/fixtures/transformation/esnext-es6-templates/nested-interpolation.js @@ -0,0 +1,4 @@ +assert.strictEqual( + `a${1}b${`${1+1}c`}3`, + 'a1b2c3' +); diff --git a/test/fixtures/transformation/esnext-es6-templates/no-interpolation.js b/test/fixtures/transformation/esnext-es6-templates/no-interpolation.js new file mode 100644 index 0000000000..1854b04ff5 --- /dev/null +++ b/test/fixtures/transformation/esnext-es6-templates/no-interpolation.js @@ -0,0 +1,2 @@ +var s = `str`; +assert.equal(s, 'str'); diff --git a/test/fixtures/transformation/esnext-es6-templates/raw-tagged-template-expression.js b/test/fixtures/transformation/esnext-es6-templates/raw-tagged-template-expression.js new file mode 100644 index 0000000000..831ad050ab --- /dev/null +++ b/test/fixtures/transformation/esnext-es6-templates/raw-tagged-template-expression.js @@ -0,0 +1,6 @@ +function r(strings) { + assert.equal(strings.raw[0], '\\n'); + return strings.raw.join(''); +} + +assert.equal(r `\n`, '\\n'); diff --git a/test/fixtures/transformation/esnext-es6-templates/simple-interpolation.js b/test/fixtures/transformation/esnext-es6-templates/simple-interpolation.js new file mode 100644 index 0000000000..b96a02a543 --- /dev/null +++ b/test/fixtures/transformation/esnext-es6-templates/simple-interpolation.js @@ -0,0 +1,2 @@ +var s = `1 + 1 = ${1 + 1}`; +assert.equal(s, '1 + 1 = 2'); diff --git a/test/fixtures/transformation/esnext-es6-templates/tagged-template-expression.js b/test/fixtures/transformation/esnext-es6-templates/tagged-template-expression.js new file mode 100644 index 0000000000..5b894c55ac --- /dev/null +++ b/test/fixtures/transformation/esnext-es6-templates/tagged-template-expression.js @@ -0,0 +1,26 @@ +function tag(strings) { + var values = [].slice.call(arguments, 1); + assert.equal(strings[0], 'a'); + assert.equal(strings[1], 'b'); + assert.equal(values[0], 42); + return 'whatever'; +} +assert.equal(tag `a${ 42 }b`, 'whatever'); + +function tagInterpolateFirst(strings) { + var values = [].slice.call(arguments, 1); + assert.equal(strings[0], ''); + assert.equal(strings[1], 'b'); + assert.equal(values[0], 42); + return 'whatever'; +} +assert.equal(tagInterpolateFirst `${ 42 }b`, 'whatever'); + +function tagInterpolateLast(strings) { + var values = [].slice.call(arguments, 1); + assert.equal(strings[0], 'a'); + assert.equal(strings[1], ''); + assert.equal(values[0], 42); + return 'whatever'; +} +assert.equal(tagInterpolateLast `a${ 42 }`, 'whatever'); From 0c0f40d14a9b3300c0310475f3f54814a1a3c281 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Sun, 4 Jan 2015 07:58:49 +1100 Subject: [PATCH 02/14] only automatically assume test is exec if it has a js extension --- test/_helper.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/_helper.js b/test/_helper.js index 8273a11443..6f5afdd93b 100644 --- a/test/_helper.js +++ b/test/_helper.js @@ -49,7 +49,7 @@ exports.get = function (entryName) { if (fs.statSync(taskDir).isFile()) { var ext = path.extname(taskDir); - if (ext === ".json") return; + if (ext !== ".js") return; execLoc = taskDir; } From 7f4efecb7db47821cb72ab692a7e40398b1ae054 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Sun, 4 Jan 2015 07:59:43 +1100 Subject: [PATCH 03/14] support for CallExpression in Scope.prototype.generateUidBasedOnNode --- lib/6to5/traverse/scope.js | 47 +++++++------------ .../accessing-super-class/expected.js | 4 +- .../assignment-expression/expected.js | 4 +- .../expected.js | 16 +++---- .../playground/method-binding/expected.js | 4 +- 5 files changed, 31 insertions(+), 44 deletions(-) diff --git a/lib/6to5/traverse/scope.js b/lib/6to5/traverse/scope.js index f6cc050998..eaa82a51b2 100644 --- a/lib/6to5/traverse/scope.js +++ b/lib/6to5/traverse/scope.js @@ -63,38 +63,29 @@ Scope.prototype.generateUidBasedOnNode = function (parent, file) { node = parent.left; } else if (t.isVariableDeclarator(parent)) { node = parent.id; - } - - var id = "ref"; - - if (t.isProperty(node)) { + } else if (t.isProperty(node)) { node = node.key; } - if (t.isIdentifier(node)) { - id = node.name; - } else if (t.isLiteral(node)) { - id = node.value; - } else if (t.isMemberExpression(node)) { - var parts = []; + var parts = []; - var add = function (node) { - if (t.isMemberExpression(node)) { - add(node.object); - add(node.property); - } else if (t.isIdentifier(node)) { - parts.push(node.name); - } else if (t.isLiteral(node)) { - parts.push(node.value); - } - }; + var add = function (node) { + if (t.isMemberExpression(node)) { + add(node.object); + add(node.property); + } else if (t.isIdentifier(node)) { + parts.push(node.name); + } else if (t.isLiteral(node)) { + parts.push(node.value); + } else if (t.isCallExpression(node)) { + add(node.callee); + } + }; - add(node); + add(node); - id = parts.join("$"); - } - - id = id.replace(/^_/, ""); + var id = parts.join("$"); + id = id.replace(/^_/, "") || "ref"; return file.generateUidIdentifier(id, this); }; @@ -108,10 +99,6 @@ Scope.prototype.generateUidBasedOnNode = function (parent, file) { */ Scope.prototype.generateTempBasedOnNode = function (node, file) { - if (!t.isIdentifier(node) && !t.isMemberExpression(node)) { - throw new TypeError("Invalid node type " + JSON.stringify(node.type) + " passed to Scope.prototype.generateTempBasedOnNode"); - } - if (t.isIdentifier(node) && this.has(node.name, true)) { return null; } diff --git a/test/fixtures/transformation/es6-classes/accessing-super-class/expected.js b/test/fixtures/transformation/es6-classes/accessing-super-class/expected.js index 1eec391c5e..14f12f07e2 100644 --- a/test/fixtures/transformation/es6-classes/accessing-super-class/expected.js +++ b/test/fixtures/transformation/es6-classes/accessing-super-class/expected.js @@ -22,8 +22,8 @@ var Test = (function () { _Foo.prototype.test.call(this); foob(_Foo); - _Foo.call.apply(null, [this].concat(_slice.call(arguments))); - _Foo.call.apply(null, [this, "test"].concat(_slice.call(arguments))); + _Foo.call.apply(_Foo, [this].concat(_slice.call(arguments))); + _Foo.call.apply(_Foo, [this, "test"].concat(_slice.call(arguments))); (_Foo$prototype$test = _Foo.prototype.test).call.apply(_Foo$prototype$test, [this].concat(_slice.call(arguments))); (_Foo$prototype$test2 = _Foo.prototype.test).call.apply(_Foo$prototype$test2, [this, "test"].concat(_slice.call(arguments))); diff --git a/test/fixtures/transformation/optional-proto-to-assign/assignment-expression/expected.js b/test/fixtures/transformation/optional-proto-to-assign/assignment-expression/expected.js index 6a66b4e972..9de37223a2 100644 --- a/test/fixtures/transformation/optional-proto-to-assign/assignment-expression/expected.js +++ b/test/fixtures/transformation/optional-proto-to-assign/assignment-expression/expected.js @@ -1,6 +1,6 @@ "use strict"; -var _foo, _foo$bar, _foo2; +var _foo, _foo$bar, _foo$bar2; var _defaults = function (obj, defaults) { for (var key in defaults) { if (obj[key] === undefined) { @@ -15,4 +15,4 @@ console.log((_foo = foo, _defaults(_foo, bar), _foo)); console.log((_foo$bar = foo[bar], _defaults(_foo$bar, bar), _foo$bar)); -console.log((_foo2 = foo[bar()], _defaults(_foo2, bar), _foo2)); +console.log((_foo$bar2 = foo[bar()], _defaults(_foo$bar2, bar), _foo$bar2)); diff --git a/test/fixtures/transformation/playground/memoization-assignment-operator/expected.js b/test/fixtures/transformation/playground/memoization-assignment-operator/expected.js index 4d9647c912..fbb64ac4f8 100644 --- a/test/fixtures/transformation/playground/memoization-assignment-operator/expected.js +++ b/test/fixtures/transformation/playground/memoization-assignment-operator/expected.js @@ -1,6 +1,6 @@ "use strict"; -var _obj2, _obj4, _ref2, _obj6, _ref4; +var _obj2, _obj4, _x2, _obj$y2, _x4; var _hasOwn = Object.prototype.hasOwnProperty; var obj = {}; @@ -11,17 +11,17 @@ if (!_hasOwn.call(_obj, "x")) _obj.x = 2; console.log((_obj2 = obj, !_hasOwn.call(_obj2, "x") && (_obj2.x = 2), _obj2.x)); var _obj3 = obj; -var _ref = x(); +var _x = x(); -if (!_hasOwn.call(_obj3, _ref)) _obj3[_ref] = 2; +if (!_hasOwn.call(_obj3, _x)) _obj3[_x] = 2; -console.log((_obj4 = obj, _ref2 = x(), !_hasOwn.call(_obj4, _ref2) && (_obj4[_ref2] = 2), _obj4[_ref2])); +console.log((_obj4 = obj, _x2 = x(), !_hasOwn.call(_obj4, _x2) && (_obj4[_x2] = 2), _obj4[_x2])); -var _obj5 = obj[y()]; -var _ref3 = x(); +var _obj$y = obj[y()]; +var _x3 = x(); -if (!_hasOwn.call(_obj5, _ref3)) _obj5[_ref3] = 2; +if (!_hasOwn.call(_obj$y, _x3)) _obj$y[_x3] = 2; -console.log((_obj6 = obj[y()], _ref4 = x(), !_hasOwn.call(_obj6, _ref4) && (_obj6[_ref4] = 2), _obj6[_ref4])); +console.log((_obj$y2 = obj[y()], _x4 = x(), !_hasOwn.call(_obj$y2, _x4) && (_obj$y2[_x4] = 2), _obj$y2[_x4])); diff --git a/test/fixtures/transformation/playground/method-binding/expected.js b/test/fixtures/transformation/playground/method-binding/expected.js index f103f4683f..156bcfffd5 100644 --- a/test/fixtures/transformation/playground/method-binding/expected.js +++ b/test/fixtures/transformation/playground/method-binding/expected.js @@ -1,11 +1,11 @@ "use strict"; -var _obj, _obj2, _obj$foo, _obj$foo2, _obj3, _args, _args2, _args3; +var _obj, _obj2, _obj$foo, _obj$foo2, _obj$foo3, _args, _args2, _args3; var fn = (_obj = obj, _obj.method.bind(_obj)); var fn = (_obj2 = obj, _obj2.method.bind(_obj2, "foob")); var fn = (_obj$foo = obj[foo], _obj$foo.method.bind(_obj$foo)); var fn = (_obj$foo2 = obj.foo, _obj$foo2.method.bind(_obj$foo2)); -var fn = (_obj3 = obj[foo()], _obj3.method.bind(_obj3)); +var fn = (_obj$foo3 = obj[foo()], _obj$foo3.method.bind(_obj$foo3)); ["foo", "bar"].map((_args = [], function (_val) { return _val.toUpperCase(); From a645ae0583acbfb6115e161fd20ea66bce848e92 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Sun, 4 Jan 2015 07:59:56 +1100 Subject: [PATCH 04/14] contextLiteral fallback in es6-spread transformer --- lib/6to5/transformation/transformers/es6-spread.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/6to5/transformation/transformers/es6-spread.js b/lib/6to5/transformation/transformers/es6-spread.js index 2415cc8a8c..bde318aa6d 100644 --- a/lib/6to5/transformation/transformers/es6-spread.js +++ b/lib/6to5/transformation/transformers/es6-spread.js @@ -83,6 +83,8 @@ exports.CallExpression = function (node, parent, file, scope) { if (temp) { callee.object = t.assignmentExpression("=", temp, callee.object); contextLiteral = temp; + } else { + contextLiteral = callee.object; } t.appendToMemberExpression(callee, t.identifier("apply")); } else { From 22eeae1a93762d0c38b5572a7993e76248ab94b2 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Sun, 4 Jan 2015 08:00:40 +1100 Subject: [PATCH 05/14] use `assert` instead of `expect` --- .../transformation/esnext-es6-rest-parameters/arrow-fn.js | 5 +---- .../transformation/esnext-es6-rest-parameters/declaration.js | 5 +---- .../transformation/esnext-es6-rest-parameters/rest.js | 5 +---- 3 files changed, 3 insertions(+), 12 deletions(-) diff --git a/test/fixtures/transformation/esnext-es6-rest-parameters/arrow-fn.js b/test/fixtures/transformation/esnext-es6-rest-parameters/arrow-fn.js index 34c96f5ecb..eb9d8ea8c5 100644 --- a/test/fixtures/transformation/esnext-es6-rest-parameters/arrow-fn.js +++ b/test/fixtures/transformation/esnext-es6-rest-parameters/arrow-fn.js @@ -1,8 +1,5 @@ -/* jshint esnext: true */ -/* global expect */ - var join = (joinStr, ...items) => { return items.join(joinStr); }; -expect(join(' ', 'a', 'b', 'c')).to.equal('a b c'); +assert.deepEqual(join(' ', 'a', 'b', 'c'), 'a b c'); diff --git a/test/fixtures/transformation/esnext-es6-rest-parameters/declaration.js b/test/fixtures/transformation/esnext-es6-rest-parameters/declaration.js index 1cc45ac46f..2d3ca5d283 100644 --- a/test/fixtures/transformation/esnext-es6-rest-parameters/declaration.js +++ b/test/fixtures/transformation/esnext-es6-rest-parameters/declaration.js @@ -1,8 +1,5 @@ -/* jshint esnext: true */ -/* global expect */ - function join(joinStr, ...items) { return items.join(joinStr); } -expect(join(' ', 'a', 'b', 'c')).to.equal('a b c'); +assert.deepEqual(join(' ', 'a', 'b', 'c'), 'a b c'); diff --git a/test/fixtures/transformation/esnext-es6-rest-parameters/rest.js b/test/fixtures/transformation/esnext-es6-rest-parameters/rest.js index 9d0e63e85d..769bf2d2a4 100644 --- a/test/fixtures/transformation/esnext-es6-rest-parameters/rest.js +++ b/test/fixtures/transformation/esnext-es6-rest-parameters/rest.js @@ -1,8 +1,5 @@ -/* jshint esnext: true */ -/* global expect */ - var join = function(joinStr, ...items) { return items.join(joinStr); }; -expect(join(' ', 'a', 'b', 'c')).to.equal('a b c'); +assert.deepEqual(join(' ', 'a', 'b', 'c'), 'a b c'); From 7ab6df093bad0ecf1af24df65465b23634566410 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Sun, 4 Jan 2015 08:00:49 +1100 Subject: [PATCH 06/14] use `Symbol.iterator` instead of `@@iterator` --- test/fixtures/transformation/esnext-es6-spread/iterator.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/test/fixtures/transformation/esnext-es6-spread/iterator.js b/test/fixtures/transformation/esnext-es6-spread/iterator.js index 438e7564de..6e5ef15ba2 100644 --- a/test/fixtures/transformation/esnext-es6-spread/iterator.js +++ b/test/fixtures/transformation/esnext-es6-spread/iterator.js @@ -1,8 +1,5 @@ -function Symbol() {} -Symbol.iterator = '@@iterator'; - var obj = { - '@@iterator': function() { + [Symbol.iterator]: function() { var ttl = 3; return { next: function() { From 4506e39cf5eb68898c5e58f9df77c66ff5433df0 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Sun, 4 Jan 2015 08:01:08 +1100 Subject: [PATCH 07/14] add `toString` key to instance keys as methods are enumerable --- test/fixtures/transformation/esnext-es6-classes/enumerable.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/fixtures/transformation/esnext-es6-classes/enumerable.js b/test/fixtures/transformation/esnext-es6-classes/enumerable.js index fe5c02d113..392fda2ca9 100644 --- a/test/fixtures/transformation/esnext-es6-classes/enumerable.js +++ b/test/fixtures/transformation/esnext-es6-classes/enumerable.js @@ -17,4 +17,4 @@ for (var key in point) { } assert.equal(point.toString(), '(1, 2)'); -assert.deepEqual(keys.sort(), ['x', 'y']); +assert.deepEqual(keys.sort(), ['toString', 'x', 'y']); From dea73b7186526c86a33563be95c4b211c5037814 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Sun, 4 Jan 2015 08:01:29 +1100 Subject: [PATCH 08/14] change code assertion to 6to5 output --- .../does-not-bind-this-from-standard-function.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/fixtures/transformation/esnext-es6-arrow-functions/does-not-bind-this-from-standard-function.js b/test/fixtures/transformation/esnext-es6-arrow-functions/does-not-bind-this-from-standard-function.js index c2eeddcc3e..6f3ffee93a 100644 --- a/test/fixtures/transformation/esnext-es6-arrow-functions/does-not-bind-this-from-standard-function.js +++ b/test/fixtures/transformation/esnext-es6-arrow-functions/does-not-bind-this-from-standard-function.js @@ -1,5 +1,5 @@ -var dynamicThisGetter = () => function(){ return this; }; +var dynamicThisGetter = () => function () { return this; }; assert.equal( - normalize('('+dynamicThisGetter.toString()+')'), - normalize('(function(){ return function(){ return this; }; })') + '(' + dynamicThisGetter.toString() + ')', + '(function () {\n return function () {\n return this;\n };\n})' ); From c578db7ae8d46ea343e6e69f73af8338c0b26309 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Sun, 4 Jan 2015 08:34:14 +1100 Subject: [PATCH 09/14] upgrade acorn-6to5 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 633a6517ee..e5b3f41b53 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "test": "make test" }, "dependencies": { - "acorn-6to5": "0.11.1-4", + "acorn-6to5": "0.11.1-5", "ast-types": "~0.6.1", "chokidar": "0.11.1", "commander": "2.5.0", From 4d5861cfdc39d85c415da41549df7fea0d4174e6 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Sun, 4 Jan 2015 08:34:25 +1100 Subject: [PATCH 10/14] remove invalid strict-mode es6 next class test --- .../esnext-es6-classes/strict-mode.js | 23 ------------------- 1 file changed, 23 deletions(-) delete mode 100644 test/fixtures/transformation/esnext-es6-classes/strict-mode.js diff --git a/test/fixtures/transformation/esnext-es6-classes/strict-mode.js b/test/fixtures/transformation/esnext-es6-classes/strict-mode.js deleted file mode 100644 index d3ece2608e..0000000000 --- a/test/fixtures/transformation/esnext-es6-classes/strict-mode.js +++ /dev/null @@ -1,23 +0,0 @@ -class StrictModeTest { - test() { - var implicitThisInsideClassBody = (function() { - return this; - })(); - assert.strictEqual( - implicitThisInsideClassBody, - undefined, - 'implicit `this` inside class body is undefined' - ); - } -} - -new StrictModeTest().test(); - -var implicitThisOutsideClass = (function() { - return this; -})(); -assert.notStrictEqual( - implicitThisOutsideClass, - undefined, - 'implicit `this` outside class body is not undefined' -); From cbcad22d81c9d342dbfcbc99f4abde10861ff9ef Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Sun, 4 Jan 2015 08:35:14 +1100 Subject: [PATCH 11/14] update default parameters transformer to use `var a = arguments[0] === undefined ? 1 : arguments[0];` instead of `if (a === undefined) a = 1;` --- .../templates/default-parameter.js | 1 + .../templates/if-undefined-set-to.js | 1 - .../transformers/es6-default-parameters.js | 21 +++++++++++++++---- .../default-parameters/expected.js | 4 ++-- .../multiple/expected.js | 10 ++++----- .../es6-default-parameters/single/expected.js | 4 ++-- 6 files changed, 27 insertions(+), 14 deletions(-) create mode 100644 lib/6to5/transformation/templates/default-parameter.js delete mode 100644 lib/6to5/transformation/templates/if-undefined-set-to.js diff --git a/lib/6to5/transformation/templates/default-parameter.js b/lib/6to5/transformation/templates/default-parameter.js new file mode 100644 index 0000000000..74fecfd0f2 --- /dev/null +++ b/lib/6to5/transformation/templates/default-parameter.js @@ -0,0 +1 @@ +var VARIABLE_NAME = ARGUMENTS[ARGUMENT_KEY] === undefined ? DEFAULT_VALUE : ARGUMENTS[ARGUMENT_KEY]; diff --git a/lib/6to5/transformation/templates/if-undefined-set-to.js b/lib/6to5/transformation/templates/if-undefined-set-to.js deleted file mode 100644 index c5ed82cdf9..0000000000 --- a/lib/6to5/transformation/templates/if-undefined-set-to.js +++ /dev/null @@ -1 +0,0 @@ -if (VARIABLE === undefined) VARIABLE = DEFAULT; diff --git a/lib/6to5/transformation/transformers/es6-default-parameters.js b/lib/6to5/transformation/transformers/es6-default-parameters.js index 9715c2bbdc..ba3c0ad631 100644 --- a/lib/6to5/transformation/transformers/es6-default-parameters.js +++ b/lib/6to5/transformation/transformers/es6-default-parameters.js @@ -49,16 +49,29 @@ exports.Function = function (node, parent, file, scope) { var body = []; + var argsIdentifier = t.identifier("arguments"); + argsIdentifier._ignoreAliasFunctions = true; + + var lastNonDefaultParam = 0; + for (i in node.defaults) { def = node.defaults[i]; - if (!def) continue; + if (!def) { + lastNonDefaultParam = +i + 1; + continue; + } - body.push(util.template("if-undefined-set-to", { - VARIABLE: node.params[i], - DEFAULT: def + body.push(util.template("default-parameter", { + VARIABLE_NAME: node.params[i], + DEFAULT_VALUE: def, + ARGUMENT_KEY: t.literal(+i), + ARGUMENTS: argsIdentifier }, true)); } + // we need to cut off all trailing default parameters + node.params = node.params.slice(0, lastNonDefaultParam); + if (iife) { var container = t.functionExpression(null, [], node.body, node.generator); container._aliasFunction = true; diff --git a/test/fixtures/transformation/es6-arrow-functions/default-parameters/expected.js b/test/fixtures/transformation/es6-arrow-functions/default-parameters/expected.js index baba36b081..19d93a94d6 100644 --- a/test/fixtures/transformation/es6-arrow-functions/default-parameters/expected.js +++ b/test/fixtures/transformation/es6-arrow-functions/default-parameters/expected.js @@ -1,7 +1,7 @@ "use strict"; -var some = function (count) { - if (count === undefined) count = "30"; +var some = function () { + var count = arguments[0] === undefined ? "30" : arguments[0]; console.log("count", count); }; diff --git a/test/fixtures/transformation/es6-default-parameters/multiple/expected.js b/test/fixtures/transformation/es6-default-parameters/multiple/expected.js index 55bc52c5c9..af684c28f7 100644 --- a/test/fixtures/transformation/es6-default-parameters/multiple/expected.js +++ b/test/fixtures/transformation/es6-default-parameters/multiple/expected.js @@ -1,12 +1,12 @@ "use strict"; -var t = function (t, f) { - if (t === undefined) t = "foo"; - if (f === undefined) f = 5; +var t = function () { + var t = arguments[0] === undefined ? "foo" : arguments[0]; + var f = arguments[1] === undefined ? 5 : arguments[1]; return t + " bar " + f; }; -var a = function (t, f) { - if (f === undefined) f = 5; +var a = function (t) { + var f = arguments[1] === undefined ? 5 : arguments[1]; return t + " bar " + f; }; diff --git a/test/fixtures/transformation/es6-default-parameters/single/expected.js b/test/fixtures/transformation/es6-default-parameters/single/expected.js index 5021d6e0ab..f953c7a0a9 100644 --- a/test/fixtures/transformation/es6-default-parameters/single/expected.js +++ b/test/fixtures/transformation/es6-default-parameters/single/expected.js @@ -1,6 +1,6 @@ "use strict"; -var t = function (t) { - if (t === undefined) t = "foo"; +var t = function () { + var t = arguments[0] === undefined ? "foo" : arguments[0]; return t + " bar"; }; From 9a2fd22e91983f046adcdc44530cbd65b7a7433d Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Sun, 4 Jan 2015 08:35:28 +1100 Subject: [PATCH 12/14] add newline to esnext super change proto test --- .../transformation/esnext-es6-classes/super-change-proto.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/fixtures/transformation/esnext-es6-classes/super-change-proto.js b/test/fixtures/transformation/esnext-es6-classes/super-change-proto.js index d0012cfc0b..f7c653b460 100644 --- a/test/fixtures/transformation/esnext-es6-classes/super-change-proto.js +++ b/test/fixtures/transformation/esnext-es6-classes/super-change-proto.js @@ -7,6 +7,7 @@ class Base { class OtherBase { p() { log += '[OtherBase]'; } } + class Derived extends Base { p() { log += '[Derived]'; From 35fda899a8cf993398adff3dae874d453c56dbd1 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Sun, 4 Jan 2015 15:30:40 +1100 Subject: [PATCH 13/14] remove spec-no-duplicate-properties transformer --- lib/6to5/transformation/transform.js | 1 - .../spec-no-duplicate-properties.js | 25 ------------------- 2 files changed, 26 deletions(-) delete mode 100644 lib/6to5/transformation/transformers/spec-no-duplicate-properties.js diff --git a/lib/6to5/transformation/transform.js b/lib/6to5/transformation/transform.js index e78a0ea3b1..bf647e1f69 100644 --- a/lib/6to5/transformation/transform.js +++ b/lib/6to5/transformation/transform.js @@ -42,7 +42,6 @@ _.each({ // spec specBlockHoistFunctions: require("./transformers/spec-block-hoist-functions"), specNoForInOfAssignment: require("./transformers/spec-no-for-in-of-assignment"), - specNoDuplicateProperties: require("./transformers/spec-no-duplicate-properties"), // playground methodBinding: require("./transformers/playground-method-binding"), diff --git a/lib/6to5/transformation/transformers/spec-no-duplicate-properties.js b/lib/6to5/transformation/transformers/spec-no-duplicate-properties.js deleted file mode 100644 index 6c7e93e761..0000000000 --- a/lib/6to5/transformation/transformers/spec-no-duplicate-properties.js +++ /dev/null @@ -1,25 +0,0 @@ -var t = require("../../types"); - -exports.ObjectExpression = function (node, parent, file) { - var keys = []; - - for (var i in node.properties) { - var prop = node.properties[i]; - if (prop.computed || prop.kind !== "init") continue; - - var key = prop.key; - if (t.isIdentifier(key)) { - key = key.name; - } else if (t.isLiteral(key)) { - key = key.value; - } else { - continue; - } - - if (keys.indexOf(key) >= 0) { - throw file.errorWithNode(prop.key, "Duplicate property key"); - } else { - keys.push(key); - } - } -}; From ccabb91f6932bcd51212dbb0ad3a766806136baf Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Sun, 4 Jan 2015 15:30:59 +1100 Subject: [PATCH 14/14] add back deleted object-define-properties-closure template --- .../templates/object-define-properties-closure.js | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 lib/6to5/transformation/templates/object-define-properties-closure.js diff --git a/lib/6to5/transformation/templates/object-define-properties-closure.js b/lib/6to5/transformation/templates/object-define-properties-closure.js new file mode 100644 index 0000000000..a4e51eaf06 --- /dev/null +++ b/lib/6to5/transformation/templates/object-define-properties-closure.js @@ -0,0 +1,5 @@ + +(function (KEY) { + CONTENT; + return KEY; +})(OBJECT);