diff --git a/tools/transpiler/src/ast/named_params.js b/tools/transpiler/src/ast/named_params.js deleted file mode 100644 index 3bbc19a5dd..0000000000 --- a/tools/transpiler/src/ast/named_params.js +++ /dev/null @@ -1,16 +0,0 @@ -import {ParseTree} from 'traceur/src/syntax/trees/ParseTree'; - -export class NamedParams extends ParseTree { - constructor(location, propertyNameAndValues) { - this.location = location; - this.propertyNameAndValues = propertyNameAndValues; - } - - visit(visitor) { - visitor.visitNamedParamsExpression(this); - } - - transform(transformer) { - return this; - } -} diff --git a/tools/transpiler/src/ast/object_pattern_binding_element.js b/tools/transpiler/src/ast/object_pattern_binding_element.js deleted file mode 100644 index 6bcbf67bf2..0000000000 --- a/tools/transpiler/src/ast/object_pattern_binding_element.js +++ /dev/null @@ -1,7 +0,0 @@ -import {BindingElement} from 'traceur/src/syntax/trees/ParseTrees'; - -export class ObjectPatternBindingElement extends BindingElement { - visit(visitor) { - visitor.visitObjectPatternBindingElement(this); - } -} diff --git a/tools/transpiler/src/codegeneration/NamedParamsTransformer.js b/tools/transpiler/src/codegeneration/NamedParamsTransformer.js index 9dbae8c25c..22bd7b4a3f 100644 --- a/tools/transpiler/src/codegeneration/NamedParamsTransformer.js +++ b/tools/transpiler/src/codegeneration/NamedParamsTransformer.js @@ -1,12 +1,15 @@ -import {ParseTreeTransformer} from 'traceur/src/codegeneration/ParseTreeTransformer'; +import {ParseTreeTransformer} from './ParseTreeTransformer'; + import { BINDING_ELEMENT, OBJECT_PATTERN, OBJECT_LITERAL_EXPRESSION } from 'traceur/src/syntax/trees/ParseTreeType'; -import {NamedParams} from '../ast/named_params'; -import {ObjectPatternBindingElement} from '../ast/object_pattern_binding_element'; +import { + NamedParameterList, + ObjectPatternBindingElement +} from '../syntax/trees/ParseTrees'; /** * Transforms maps into named parameters: @@ -22,6 +25,8 @@ import {ObjectPatternBindingElement} from '../ast/object_pattern_binding_element */ export class NamedParamsTransformer extends ParseTreeTransformer { /** + * Transform function calls. + * * @param {CallExpression} tree * @return {ParseTree} */ @@ -58,10 +63,12 @@ export class NamedParamsTransformer extends ParseTreeTransformer { _replaceLastArgWithNamedParams(tree) { var args = tree.args.args; var last = this._last(args); - args[args.length - 1] = new NamedParams(last.location, last.propertyNameAndValues); + args[args.length - 1] = new NamedParameterList(last.location, last.propertyNameAndValues); } /** + * Transform function declaration. + * * @param {ObjectPattern} tree * @return {ParseTree} */ diff --git a/tools/transpiler/src/codegeneration/ParseTreeTransformer.js b/tools/transpiler/src/codegeneration/ParseTreeTransformer.js index 449de13c6b..d052bc0cb1 100644 --- a/tools/transpiler/src/codegeneration/ParseTreeTransformer.js +++ b/tools/transpiler/src/codegeneration/ParseTreeTransformer.js @@ -4,7 +4,9 @@ import { import { ClassFieldDeclaration, - PropertyConstructorAssignment + PropertyConstructorAssignment, + NamedParameterList, + ObjectPatternBindingElement } from '../syntax/trees/ParseTrees' export class ParseTreeTransformer extends TraceurParseTreeTransformer { @@ -28,4 +30,21 @@ export class ParseTreeTransformer extends TraceurParseTreeTransformer { tree.name, tree.parameterList, tree.typeAnnotation, tree.annotations, tree.body, tree.isConst, initializerList); } -} \ No newline at end of file + + transformNamedParameterList(tree) { + var nvPairs = this.transformList(tree.parameterNameAndValues); + if (nvPairs === tree.parameterNameAndValues) { + return tree; + } + return new NamedParameterList(tree.location, nvPairs); + } + + transformObjectPatternBindingElement(tree) { + var binding = this.transformAny(tree.binding); + var initializer = this.transformAny(tree.initializer); + if (binding === tree.binding && initializer === tree.initializer) { + return tree; + } + return new ObjectPatternBindingElement(tree.location, binding, initializer); + } +} diff --git a/tools/transpiler/src/outputgeneration/DartParseTreeWriter.js b/tools/transpiler/src/outputgeneration/DartParseTreeWriter.js index d60b5da845..e1f76af7cd 100644 --- a/tools/transpiler/src/outputgeneration/DartParseTreeWriter.js +++ b/tools/transpiler/src/outputgeneration/DartParseTreeWriter.js @@ -323,8 +323,8 @@ export class DartParseTreeWriter extends JavaScriptParseTreeWriter { this.writeSpace_() } - visitNamedParamsExpression(tree) { - this.writeList_(tree.propertyNameAndValues, COMMA, false); + visitNamedParameterList(tree) { + this.writeList_(tree.parameterNameAndValues, COMMA, false); } toString() { diff --git a/tools/transpiler/src/syntax/trees/ParseTreeType.js b/tools/transpiler/src/syntax/trees/ParseTreeType.js index c0eaaf890c..9fe08500df 100644 --- a/tools/transpiler/src/syntax/trees/ParseTreeType.js +++ b/tools/transpiler/src/syntax/trees/ParseTreeType.js @@ -1,2 +1,4 @@ export var CLASS_FIELD_DECLARATION = 'CLASS_FIELD_DECLARATION'; -export var PROPERTY_CONSTRUCTOR_ASSIGNMENT = 'PROPERTY_CONSTRUCTOR_ASSIGNMENT'; \ No newline at end of file +export var PROPERTY_CONSTRUCTOR_ASSIGNMENT = 'PROPERTY_CONSTRUCTOR_ASSIGNMENT'; +export var NAMED_PARAMETER_LIST = 'NAMED_PARAMETER_LIST'; +export var OBJECT_PATTERN_BINDING_ELEMENT = 'OBJECT_PATTERN_BINDING_ELEMENT'; diff --git a/tools/transpiler/src/syntax/trees/ParseTrees.js b/tools/transpiler/src/syntax/trees/ParseTrees.js index c3b5a52f23..8c32451029 100644 --- a/tools/transpiler/src/syntax/trees/ParseTrees.js +++ b/tools/transpiler/src/syntax/trees/ParseTrees.js @@ -4,9 +4,7 @@ import {PropertyMethodAssignment} from 'traceur/src/syntax/trees/ParseTrees'; import * as ParseTreeType from './ParseTreeType'; -/** - * Property declaration - */ +// Class field declaration export class ClassFieldDeclaration extends ParseTree { constructor(location, lvalue, typeAnnotation, isFinal) { this.location = location; @@ -30,9 +28,7 @@ export class ClassFieldDeclaration extends ParseTree { var CLASS_FIELD_DECLARATION = ParseTreeType.CLASS_FIELD_DECLARATION; -/** - * Class constructor - */ +// Class constructor export class PropertyConstructorAssignment extends PropertyMethodAssignment { /** * @param {SourceRange} location @@ -78,3 +74,73 @@ export class PropertyConstructorAssignment extends PropertyMethodAssignment { var PROPERTY_CONSTRUCTOR_ASSIGNMENT = ParseTreeType.PROPERTY_CONSTRUCTOR_ASSIGNMENT; +// Named parameters +export class NamedParameterList extends ParseTree { + /** + * @param {SourceRange} location + * @param {Array.} parameterNameAndValues + */ + constructor(location, parameterNameAndValues) { + this.location = location; + this.parameterNameAndValues = parameterNameAndValues; + } + + /** + * @param {ParseTreeTransformer} transformer + */ + transform(transformer) { + return transformer.transformNamedParameterList(this); + } + + /** + * @param {ParseTreeVisitor} visitor + */ + visit(visitor) { + visitor.visitNamedParameterList(this); + } + + /** + * @type {ParseTreeType} + */ + get type() { + return NAMED_PARAMETER_LIST; + } +} + +var NAMED_PARAMETER_LIST = ParseTreeType.NAMED_PARAMETER_LIST; + +// Object pattern binding element +export class ObjectPatternBindingElement extends ParseTree { + /** + * @param {SourceRange} location + * @param {BindingIdentifier|ObjectPattern|ArrayPattern} binding + * @param {ParseTree} initializer + */ + constructor(location, binding, initializer) { + this.location = location; + this.binding = binding; + this.initializer = initializer; + } + + /** + * @param {ParseTreeTransformer} transformer + */ + transform(transformer) { + return transformer.transformObjectPatternBindingElement(this); + } + + /** + * @param {ParseTreeVisitor} visitor + */ + visit(visitor) { + visitor.visitObjectPatternBindingElement(this); + } + + /** + * @type {ParseTreeType} + */ + get type() { + return OBJECT_PATTERN_BINDING_ELEMENT; + } +} +var OBJECT_PATTERN_BINDING_ELEMENT = ParseTreeType.OBJECT_PATTERN_BINDING_ELEMENT;