From 9d21a6f40d4c5abb7aae3dab87867e64360fdc5a Mon Sep 17 00:00:00 2001 From: Caitlin Potter Date: Tue, 24 Mar 2015 11:01:26 -0400 Subject: [PATCH] chore(package.json): upgrade traceur to v0.0.87 Fix in source-map test to follow through the sourcemap chain. --- docs/dgeni-package/services/atParser.js | 9 ++++-- docs/dgeni-package/services/traceurOptions.js | 3 +- .../src/core/annotations/annotations.js | 2 +- modules/angular2/src/directives/for.js | 1 - modules/angular2/src/forms/directives.js | 3 -- modules/angular2/src/forms/model.js | 2 +- .../angular2/test/forms/integration_spec.js | 1 - .../e2e_test/sourcemap/sourcemap_spec.es6 | 9 +++++- package.json | 4 +-- tools/transpiler/index.js | 31 +++---------------- tools/transpiler/spec/classes_spec.js | 2 +- .../src/codegeneration/ClassTransformer.js | 1 + .../src/codegeneration/DartTransformer.js | 3 +- .../src/codegeneration/ExportTransformer.js | 1 + tools/transpiler/src/compiler.js | 12 +++---- tools/transpiler/src/parser.js | 4 +-- .../src/patch/TypeToExpressionTransformer.js | 4 +++ .../transpiler/src/syntax/trees/ParseTrees.js | 6 ++-- tools/transpiler/unittest/transpilertests.js | 10 +++--- 19 files changed, 52 insertions(+), 56 deletions(-) diff --git a/docs/dgeni-package/services/atParser.js b/docs/dgeni-package/services/atParser.js index 60afd5a343..1ffb67eccb 100644 --- a/docs/dgeni-package/services/atParser.js +++ b/docs/dgeni-package/services/atParser.js @@ -34,13 +34,18 @@ module.exports = function atParser(AttachCommentTreeVisitor, SourceFile, Traceur var sourceFile = new SourceFile(moduleName, fileInfo.content); var comments = []; var moduleTree; - var parser = new TraceurParser(sourceFile); + var errorReporter = { + reportError: function(position, message) { + } + }; + + traceurOptions.setFromObject(service.traceurOptions); + var parser = new TraceurParser(sourceFile, errorReporter, traceurOptions); // Configure the parser parser.handleComment = function(range) { comments.push({ range: range }); }; - traceurOptions.setFromObject(service.traceurOptions); try { // Parse the file as a module, attaching the comments diff --git a/docs/dgeni-package/services/traceurOptions.js b/docs/dgeni-package/services/traceurOptions.js index 681038c5e9..750da8590c 100644 --- a/docs/dgeni-package/services/traceurOptions.js +++ b/docs/dgeni-package/services/traceurOptions.js @@ -1,3 +1,4 @@ module.exports = function traceurOptions() { - return System.get(System.map.traceur + '/src/Options.js').options; + var Options = System.get(System.map.traceur + "/src/Options.js").Options; + return new Options(); }; \ No newline at end of file diff --git a/modules/angular2/src/core/annotations/annotations.js b/modules/angular2/src/core/annotations/annotations.js index 7cf428c3e4..b8f95c06ca 100644 --- a/modules/angular2/src/core/annotations/annotations.js +++ b/modules/angular2/src/core/annotations/annotations.js @@ -717,13 +717,13 @@ export class Decorator extends Directive { compileChildren:boolean }={}) { - this.compileChildren = compileChildren; super({ selector: selector, bind: bind, events: events, lifecycle: lifecycle }); + this.compileChildren = compileChildren; } } diff --git a/modules/angular2/src/directives/for.js b/modules/angular2/src/directives/for.js index 01fd4428bf..ef6832c00a 100644 --- a/modules/angular2/src/directives/for.js +++ b/modules/angular2/src/directives/for.js @@ -13,7 +13,6 @@ import {ListWrapper} from 'angular2/src/facade/collection'; export class For { viewContainer: ViewContainer; constructor(viewContainer:ViewContainer) { - super(); this.viewContainer = viewContainer; } diff --git a/modules/angular2/src/forms/directives.js b/modules/angular2/src/forms/directives.js index 1debb02cb6..410b089e2e 100644 --- a/modules/angular2/src/forms/directives.js +++ b/modules/angular2/src/forms/directives.js @@ -22,7 +22,6 @@ export class DefaultValueAccessor { onChange:Function; constructor(@PropertySetter('value') setValueProperty:Function) { - super(); this._setValueProperty = setValueProperty; this.onChange = (_) => {}; } @@ -44,7 +43,6 @@ export class CheckboxControlValueAccessor { onChange:Function; constructor(cd:ControlDirective, @PropertySetter('checked') setCheckedProperty:Function) { - super(); this._setCheckedProperty = setCheckedProperty; this.onChange = (_) => {}; cd.valueAccessor = this; //ControlDirective should inject CheckboxControlDirective @@ -126,7 +124,6 @@ export class ControlGroupDirective { _directives:List; constructor(@Optional() @Ancestor() groupDirective:ControlGroupDirective) { - super(); this._groupDirective = groupDirective; this._directives = ListWrapper.create(); } diff --git a/modules/angular2/src/forms/model.js b/modules/angular2/src/forms/model.js index 7db069a1a4..f0959354f4 100644 --- a/modules/angular2/src/forms/model.js +++ b/modules/angular2/src/forms/model.js @@ -228,4 +228,4 @@ export class ControlArray extends AbstractControl { this._errors = this.validator(this); this._status = isPresent(this._errors) ? INVALID : VALID; } -} \ No newline at end of file +} diff --git a/modules/angular2/test/forms/integration_spec.js b/modules/angular2/test/forms/integration_spec.js index 4a7123e9dd..0561ba4bf8 100644 --- a/modules/angular2/test/forms/integration_spec.js +++ b/modules/angular2/test/forms/integration_spec.js @@ -415,7 +415,6 @@ class WrappedValue { onChange:Function; constructor(cd:ControlDirective, @PropertySetter('value') setProperty:Function) { - super(); this._setProperty = setProperty; cd.valueAccessor = this; } diff --git a/modules/examples/e2e_test/sourcemap/sourcemap_spec.es6 b/modules/examples/e2e_test/sourcemap/sourcemap_spec.es6 index 7d35609620..844a358627 100644 --- a/modules/examples/e2e_test/sourcemap/sourcemap_spec.es6 +++ b/modules/examples/e2e_test/sourcemap/sourcemap_spec.es6 @@ -23,6 +23,7 @@ describe('sourcemaps', function () { expect(errorLine).not.toBeNull(); expect(errorColumn).not.toBeNull(); + var sourceMapData = fs.readFileSync( 'dist/js/prod/es5/examples/src/sourcemap/index.js.map'); var decoder = new sourceMap.SourceMapConsumer(JSON.parse(sourceMapData)); @@ -32,9 +33,15 @@ describe('sourcemaps', function () { column: errorColumn }); + var finalMapData = fs.readFileSync( + 'dist/js/prod/es6/examples/src/sourcemap/index.map'); + var finalDecoder = new sourceMap.SourceMapConsumer(JSON.parse(finalMapData)); + + var finalPosition = finalDecoder.originalPositionFor(originalPosition); + var sourceCodeLines = fs.readFileSync('modules/examples/src/sourcemap/index.js', {encoding: 'UTF-8'}).split('\n'); - expect(sourceCodeLines[originalPosition.line - 1]) + expect(sourceCodeLines[finalPosition.line - 1]) .toMatch(/throw new BaseException\(\'Sourcemap test\'\)/); }); }); diff --git a/package.json b/package.json index df7ff5e534..28d9229b7f 100644 --- a/package.json +++ b/package.json @@ -26,8 +26,8 @@ "dependencies": { "es6-module-loader": "^0.9.2", "systemjs": "^0.9.1", - "traceur": "0.0.82", "rx": "2.4.6", + "traceur": "0.0.87", "which": "~1", "zone.js": "0.4.0", "googleapis": "1.0.x", @@ -54,7 +54,7 @@ "gulp-shell": "^0.2.10", "gulp-sourcemaps": "1.3.*", "gulp-template": "^3.0.0", - "gulp-traceur": "0.16.*", + "gulp-traceur": "0.17.*", "gulp-ts2dart": "^1.0.0", "gulp-webserver": "^0.8.7", "js-yaml": "^3.2.7", diff --git a/tools/transpiler/index.js b/tools/transpiler/index.js index 3e6366780b..67e6dd4739 100644 --- a/tools/transpiler/index.js +++ b/tools/transpiler/index.js @@ -40,12 +40,9 @@ exports.compile = function compile(options, paths, source, reloadTraceur) { moduleName = moduleName || inputPath; moduleName = moduleName.replace(/\.\w*$/, ''); - var localOptions = extend(options, { - moduleName: moduleName - }); var CompilerCls = System.get('transpiler/src/compiler').Compiler; - var compiler = new CompilerCls(localOptions); + var compiler = new CompilerCls(options, moduleName); var result = { js: compiler.compile(source, inputPath, outputPath), sourceMap: null @@ -56,7 +53,7 @@ exports.compile = function compile(options, paths, source, reloadTraceur) { result.sourceMap = JSON.parse(sourceMapString); } - if (localOptions.outputLanguage === 'es6' && source.indexOf('$traceurRuntime') === -1) { + if (options.outputLanguage === 'es6' && source.indexOf('$traceurRuntime') === -1) { assert(result.js.indexOf('$traceurRuntime') === -1, 'Transpile to ES6 must not add references to $traceurRuntime, ' + inputPath + ' is transpiled to:\n' + result.js); @@ -94,7 +91,6 @@ function reloadCompiler(reloadTraceur) { useRttsAssertModuleForConvertingTypesToExpressions(); supportSuperCallsInEs6Patch(); convertTypesToExpressionsInEs6Patch(); - removeNonStaticFieldDeclarationsInEs6Patch(); disableGetterSetterAssertionPatch(); patchCommonJSModuleTransformerToSupportExportStar(); } @@ -111,9 +107,7 @@ function loadModule(filepath, transpile) { .replace(__dirname, 'transpiler') .replace(/\\/g, '/') .replace(/\.\w*$/, ''); - data = (new traceur.NodeCompiler( - extend(SELF_COMPILE_OPTIONS, { moduleName: moduleName } ) - )).compile(data, filepath, filepath); + data = traceur.compile(data, SELF_COMPILE_OPTIONS, moduleName); } ('global', eval)(data); @@ -157,30 +151,15 @@ function convertTypesToExpressionsInEs6Patch() { PureES6Transformer.prototype.transform = function() { if (!this._patched) { this._patched = true; + var self = this; this.treeTransformers_.splice(0,0, function(tree) { - return new TypeToExpressionTransformer(new UniqueIdentifierGenerator(), this.reporter_).transformAny(tree); + return new TypeToExpressionTransformer(new UniqueIdentifierGenerator(), self.reporter_, self.options_).transformAny(tree); }); } return _transform.apply(this, arguments); }; } -// TODO(tbosch): Don't write field declarations in classes when we output to ES6. -// This just patches the writer and does not support moving initializers to the constructor. -// See src/codegeneration/ClassTransformer.js for how to support initializers as well. -// see https://github.com/google/traceur-compiler/issues/1708 -function removeNonStaticFieldDeclarationsInEs6Patch() { - var traceurVersion = System.map['traceur']; - var ParseTreeWriter = System.get(traceurVersion+'/src/outputgeneration/ParseTreeWriter').ParseTreeWriter; - var options = System.get(traceurVersion + "/src/Options.js").options; - var _visitPropertyVariableDeclaration = ParseTreeWriter.prototype.visitPropertyVariableDeclaration; - ParseTreeWriter.prototype.visitPropertyVariableDeclaration = function() { - if (options.outputLanguage !== 'es6') { - return _visitPropertyVariableDeclaration.apply(this, arguments); - } - }; -} - // TODO(tbosch): Disable getter/setters for assertions until traceur has a flag // that allows to disable them while keeping assertions and member fields enabled. // see https://github.com/google/traceur-compiler/issues/1625 diff --git a/tools/transpiler/spec/classes_spec.js b/tools/transpiler/spec/classes_spec.js index d0e0f7263c..c518c2dfc6 100644 --- a/tools/transpiler/spec/classes_spec.js +++ b/tools/transpiler/spec/classes_spec.js @@ -19,8 +19,8 @@ class SubFoo extends Foo { c; constructor(a, b) { - this.c = 3; super(a, b); + this.c = 3; } } diff --git a/tools/transpiler/src/codegeneration/ClassTransformer.js b/tools/transpiler/src/codegeneration/ClassTransformer.js index cd4496f797..f289ff8a5c 100644 --- a/tools/transpiler/src/codegeneration/ClassTransformer.js +++ b/tools/transpiler/src/codegeneration/ClassTransformer.js @@ -38,6 +38,7 @@ import { */ export class ClassTransformer extends ParseTreeTransformer { constructor(idGenerator, reporter) { + super(idGenerator); this.reporter_ = reporter; } diff --git a/tools/transpiler/src/codegeneration/DartTransformer.js b/tools/transpiler/src/codegeneration/DartTransformer.js index 94afc881bd..9c59249c84 100644 --- a/tools/transpiler/src/codegeneration/DartTransformer.js +++ b/tools/transpiler/src/codegeneration/DartTransformer.js @@ -16,8 +16,9 @@ import {DestructuringTransformer} from './DestructuringTransformer'; * Transforms ES6 + annotations to Dart code. */ export class DartTransformer extends MultiTransformer { - constructor(reporter, idGenerator = new UniqueIdentifierGenerator()) { + constructor(reporter, options) { super(reporter, options.validate); + let idGenerator = new UniqueIdentifierGenerator(); var append = (transformer) => { this.append((tree) => { diff --git a/tools/transpiler/src/codegeneration/ExportTransformer.js b/tools/transpiler/src/codegeneration/ExportTransformer.js index 8627108393..adbfdd9c2d 100644 --- a/tools/transpiler/src/codegeneration/ExportTransformer.js +++ b/tools/transpiler/src/codegeneration/ExportTransformer.js @@ -51,6 +51,7 @@ function getIndexOfFirstNonImportStatement(items) { */ export class ExportTransformer extends ParseTreeTransformer { constructor(idGenerator, reporter) { + super(idGenerator); this.reporter_ = reporter; this.importedVars_ = null; this.collectedExports_ = null; diff --git a/tools/transpiler/src/compiler.js b/tools/transpiler/src/compiler.js index 37bded0cef..b1d7ab6dfa 100644 --- a/tools/transpiler/src/compiler.js +++ b/tools/transpiler/src/compiler.js @@ -4,20 +4,19 @@ import {DartParseTreeWriter} from './outputgeneration/DartParseTreeWriter'; import {CollectingErrorReporter} from 'traceur/src/util/CollectingErrorReporter'; import {Parser} from './parser'; import {SourceFile} from 'traceur/src/syntax/SourceFile'; -import { - options as traceurOptions -} from 'traceur/src/Options'; +import {Options} from 'traceur/src/Options'; export class Compiler extends TraceurCompiler { constructor(options, sourceRoot) { super(options, sourceRoot); + this.moduleName_ = sourceRoot; } transform(tree, moduleName = undefined) { if (this.options_.outputLanguage.toLowerCase() === 'dart') { var errorReporter = new CollectingErrorReporter(); - var transformer = new DartTransformer(errorReporter); + var transformer = new DartTransformer(errorReporter, this.options_); var transformedTree = transformer.transform(tree); this.throwIfErrors(errorReporter); return transformedTree; @@ -28,7 +27,7 @@ export class Compiler extends TraceurCompiler { write(tree, outputName = undefined, sourceRoot = undefined) { if (this.options_.outputLanguage.toLowerCase() === 'dart') { - var writer = new DartParseTreeWriter(this.options_.moduleName, outputName); + var writer = new DartParseTreeWriter(this.moduleName_, outputName); writer.visitAny(tree); return writer.toString(); } else { @@ -45,13 +44,14 @@ export class Compiler extends TraceurCompiler { } this.sourceMapGenerator_ = null; + var traceurOptions = new Options(); // Here we mutate the global/module options object to be used in parsing. traceurOptions.setFromObject(this.options_); var errorReporter = new CollectingErrorReporter(); sourceName = this.sourceName(sourceName); var sourceFile = new SourceFile(sourceName, content); - var parser = new Parser(sourceFile, errorReporter); + var parser = new Parser(sourceFile, errorReporter, this.options_); var tree = this.options_.script ? parser.parseScript() : parser.parseModule(); this.throwIfErrors(errorReporter); diff --git a/tools/transpiler/src/parser.js b/tools/transpiler/src/parser.js index 6f5d9fc174..02c598adb2 100644 --- a/tools/transpiler/src/parser.js +++ b/tools/transpiler/src/parser.js @@ -4,8 +4,8 @@ import {TypeName, ImportSpecifier, ImportedBinding, BindingIdentifier} from 'tra import {PERIOD, IMPORT, STAR, AS, FROM, CLOSE_ANGLE, OPEN_ANGLE, COMMA, OPEN_CURLY, CLOSE_CURLY, COLON} from 'traceur/src/syntax/TokenType'; export class Parser extends TraceurParser { - constructor(file, errorReporter = new SyntaxErrorReporter()) { - super(file, errorReporter); + constructor(file, errorReporter = new SyntaxErrorReporter(), options) { + super(file, errorReporter, options); } // TODO: add support for object type literals to traceur! diff --git a/tools/transpiler/src/patch/TypeToExpressionTransformer.js b/tools/transpiler/src/patch/TypeToExpressionTransformer.js index e883f2449a..54bfe00986 100644 --- a/tools/transpiler/src/patch/TypeToExpressionTransformer.js +++ b/tools/transpiler/src/patch/TypeToExpressionTransformer.js @@ -16,6 +16,10 @@ import { } from 'traceur/src/codegeneration/PlaceholderParser.js'; export class TypeToExpressionTransformer extends ParseTreeTransformer { + constructor(idGenerator, reporter, options) { + super(idGenerator, reporter); + this.options_ = options; + } transformTypeName(tree) { if (tree.moduleName) { diff --git a/tools/transpiler/src/syntax/trees/ParseTrees.js b/tools/transpiler/src/syntax/trees/ParseTrees.js index 4e66fe3aaf..2f2e0fbbfc 100644 --- a/tools/transpiler/src/syntax/trees/ParseTrees.js +++ b/tools/transpiler/src/syntax/trees/ParseTrees.js @@ -63,7 +63,7 @@ export class NamedParameterList extends ParseTree { * @param {Array.} parameterNameAndValues */ constructor(location, parameterNameAndValues) { - this.location = location; + super(location); this.parameterNameAndValues = parameterNameAndValues; } @@ -105,7 +105,7 @@ export class ObjectPatternBindingElement extends ParseTree { * @param {ParseTree} initializer */ constructor(location, binding, initializer) { - this.location = location; + super(location); this.binding = binding; this.initializer = initializer; } @@ -144,7 +144,7 @@ export class ImplementsDeclaration extends ParseTree { * @param {Array.} interfaces */ constructor(location, interfaces) { - this.location = location; + super(location); this.interfaces = interfaces; } diff --git a/tools/transpiler/unittest/transpilertests.js b/tools/transpiler/unittest/transpilertests.js index 52d8dd91d7..0dec70fca0 100644 --- a/tools/transpiler/unittest/transpilertests.js +++ b/tools/transpiler/unittest/transpilertests.js @@ -111,15 +111,17 @@ describe('transpile to es6', function() { it('should allow super() calls when transpiling to ES6 with source maps', function() { options = merge(options, {sourceMaps: true}); var result = compiler.compile(options, "test.js", - "class Test {" + + "class Base {}\n" + + "class Test extends Base {" + " constructor() { super(); }" + "}"); - expect(result.js).toBe("class Test {\n" + + expect(result.js).toBe("class Base {}\n" + + "class Test extends Base {\n" + " constructor() {\n"+ " super();\n"+ " }\n"+ - "}\n\n"+ - "//# sourceMappingURL=test.map\n"); + "}\n"+ + "//# sourceMappingURL=test.js.map\n"); }); it('should convert types to expressions', function() {