Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

v2.0.0: READ FULL COMMIT MESSAGE

1) Updated traceur to latest trunk. This breaks stuff! READ COMMIT HISTORY
	`new()` is now `constructor()`
	`class method()` is now `static method()`
	more that i dont know yet.
2) Project has transitioned to be a compiler focus.
	New binaries installed, traceur and traceurc (working ver, not googles official traceurc, diff usage)
3) Restructured project files around.
	example files -> examples/
	traceur bootstrap -> split out into lib/ folder
	new bin/ dir
	example out/ dir from compiling examples/
  • Loading branch information...
commit 4e80f9938b1c94776fabea87589a965c75225dc9 1 parent 672b4a1
@aikar authored
Showing with 980 additions and 277 deletions.
  1. +29 −30 README.markdown
  2. +4 −0 bin/traceur
  3. +156 −0 bin/traceurc
  4. +4 −0 examples/test.js
  5. +26 −0 examples/testtraceur.js
  6. 0  lib/runtime.js
  7. +8 −0 lib/traceur.js
  8. +52 −0 lib/transform.js
  9. +3 −0  out/examples/test.js
  10. +39 −0 out/examples/testtraceur.js
  11. +446 −0 out/node_modules/traceur-runtime.js
  12. +5 −7 package.json
  13. +0 −5 test.js
  14. +0 −20 testtraceur.js
  15. +0 −64 traceur.js
  16. +7 −7 traceur/demo/generators.js
  17. +2 −1  traceur/demo/repl.html
  18. +14 −14 traceur/presentation/index.html
  19. +2 −1  traceur/presentation/script.js
  20. +5 −5 traceur/src/codegeneration/ClassTransformer.js
  21. +68 −9 traceur/src/codegeneration/DestructuringTransformer.js
  22. +11 −11 traceur/src/codegeneration/{ForEachTransformer.js → ForOfTransformer.js}
  23. +7 −7 traceur/src/codegeneration/GeneratorTransformPass.js
  24. +5 −26 traceur/src/codegeneration/ParseTreeFactory.js
  25. +4 −4 traceur/src/codegeneration/ParseTreeTransformer.js
  26. +7 −7 traceur/src/codegeneration/ParseTreeWriter.js
  27. +5 −5 traceur/src/codegeneration/ProgramTransformer.js
  28. +3 −3 traceur/src/codegeneration/generator/BreakContinueTransformer.js
  29. +3 −3 traceur/src/codegeneration/generator/CPSTransformer.js
  30. +1 −1  traceur/src/codegeneration/module/ModuleDefinitionVisitor.js
  31. +1 −1  traceur/src/filecompiler.js
  32. +19 −3 traceur/src/runtime/runtime.js
  33. +4 −4 traceur/src/semantics/ClassAnalyzer.js
  34. +1 −1  traceur/src/semantics/FreeVariableChecker.js
  35. +3 −3 traceur/src/semantics/VariableBinder.js
  36. +2 −2 traceur/src/semantics/symbols/AggregateSymbol.js
  37. +1 −1  traceur/src/semantics/symbols/MethodSymbol.js
  38. +2 −2 traceur/src/syntax/ParseTreeValidator.js
  39. +2 −2 traceur/src/syntax/ParseTreeVisitor.js
  40. +25 −25 traceur/src/syntax/Parser.js
  41. +1 −0  traceur/src/syntax/PredefinedName.js
  42. +1 −1  traceur/src/syntax/trees/ParseTree.js
  43. +1 −1  traceur/src/syntax/trees/ParseTrees.js
  44. +1 −1  traceur/src/traceur.js
View
59 README.markdown
@@ -5,42 +5,41 @@ Traceur provides support for Googles Traceur project which adds many enhanced
features to the JavaScript language. For full details on what all Traceur does,
visit <http://code.google.com/p/traceur-compiler/wiki/LanguageFeatures>
-## WARNING
-Traceur has a pretty big impact on performance at this time.
-If you want to use Traceur, I strongly recommend requireing() all files on process start, and understand there will be a sizable delay...
-
-For example, node-optimist at around 500 lines of code takes 176ms to translate (which doesn't even use Traceur syntax!)
-
-Use at own risk
+## NOTICE
+Version 2.0 of this package has transitioned effort to be a compiler and not a
+runtime loader. It still works just the same as a runtime loader, just really,
+DONT DO IT!
## Install
-Traceur is ready to be installed from NPM, but may also be manually added
-to your project with git submodules or a clone. First CD to your project root.
-Ensure a directory named `node_modules` exists.
+Traceur should only be installed globally to your developer system and never be
+included as part of your package. The Traceur syntax transformer is way too slow
+to use in a live system and should only be used as a compiler/tester.
- Install with NPM:
- - `npm install traceur`
-
- - Install with GIT:
- - As a submodule:
- - `git submodule add git://github.com/aikar/traceur node_modules/traceur`
- - `git submodule update --init --recursive`
- - As a plain clone:
- - `git clone git://github.com/aikar/traceur node_modules/traceur`
+ - `npm install traceur -g`
## Usage
-To use Traceur, simply require it at the start of your node.js process.
-You do not need to assign it to a variable or call any special function.
-Simply require('traceur') and then all require() statements after it may use
-Traceur syntax.
-
- require('traceur');
-
- // ./classes/MyClass.js has class MyClass { }
- MyClass = require('./classes/MyClass.js');
-
- var instance = new MyClass;
-
+Visit Traceur website as linked above for language features.
+
+Traceur module provides 2 binaries:
+
+`traceur app.js`:
+This binary will execute node but all require() statements can make use of
+traceur syntax. Note that startup will be slow as the source code is transformed!
+
+This is the same thing as calling require('traceur') then requiring your file.
+
+DO NOT USE THIS FEATURE IN A PRODUCTION APP!
+
+`traceurc inputdir/ outputdir/`: this command takes a directory and finds every
+.js file in the directory and compiles it with traceur then writes it in the same
+dir format as input, to the output dir. A small runtime library is created at
+outputdir/node_modules/traceur-runtime.js that is auto loaded by all modules.
+
+You may need to add this to your package.json so npm wont ignore it...
+(I hate that addition to npm :())
+
+USE THIS FEATURE TO DEPLOY/PUBLISH!
## License
> The MIT License
>
View
4 bin/traceur
@@ -0,0 +1,4 @@
+#!/usr/bin/env node
+var path = require('path');
+require('../')
+require(path.resolve(process.cwd(), process.argv[2]));
View
156 bin/traceurc
@@ -0,0 +1,156 @@
+#!/usr/bin/env node
+
+// Copyright 2011 Google Inc.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+(function() {
+ 'use strict';
+ var runtimestub = 'traceur = global.traceur || {};require("traceur-runtime");';
+ if (process.argv.length !== 4) {
+ console.log('Usage: traceurc inputdir/ outdir/');
+ process.exit(1);
+ }
+
+ var fs = require('fs');
+ var path = require('path');
+
+ /**
+ * Reads a script and eval's it into the global scope.
+ * TODO: this is needed for now because of how our scripts are designed.
+ * Change this once we have a module system.
+ * @param {string} filename
+ */
+ function importScript(filename) {
+ filename = path.join(__dirname + '/../traceur/src', filename);
+ var data = fs.readFileSync(filename);
+ if (!data) {
+ throw new Error('Failed to import ' + filename);
+ }
+ data = data.toString('utf8');
+ eval.call(global, data);
+ }
+
+ // Allow traceur.js to use importScript.
+ global.importScript = importScript;
+
+ importScript('./traceur.js');
+ global.traceur.semantics.FreeVariableChecker.checkProgram = function() {}
+ /**
+ * Recursively makes all directoires, similar to mkdir -p
+ * @param {string} dir
+ */
+ function mkdirRecursive(dir) {
+ var parts = path.normalize(dir).split('/');
+
+ dir = '';
+ for (var i = 0; i < parts.length; i++) {
+ dir += parts[i] + '/';
+ if (!path.existsSync(dir)) {
+ fs.mkdirSync(dir, 0x1FF);
+ }
+ }
+ }
+
+ /**
+ * Removes the common prefix of basedir and filedir from filedir
+ * @param {string} basedir
+ * @param {string} filedir
+ */
+ function removeCommonPrefix(basedir, filedir) {
+ var baseparts = basedir.split('/');
+ var fileparts = filedir.split('/');
+
+ var i = 0;
+ while (i < fileparts.length && fileparts[i] === baseparts[i]) {
+ i++;
+ }
+ return fileparts.slice(i).join('/');
+ }
+
+ function compileFiles(outputdir, filenames) {
+ var reporter = new traceur.util.ErrorReporter();
+ var project = new traceur.semantics.symbols.Project();
+
+ console.log('Reading files...');
+ var success = filenames.every(function(filename) {
+ var data = fs.readFileSync(filename);
+ if (!data) {
+ console.log('Failed to read ' + filename);
+ return false;
+ }
+ data = data.toString('utf8');
+ var sourceFile = new traceur.syntax.SourceFile(filename, data);
+ project.addFile(sourceFile);
+ return true;
+ });
+
+ if (!success) {
+ return false;
+ }
+
+ console.log('Compiling...');
+ var results = traceur.codegeneration.Compiler.compile(reporter, project);
+ if (reporter.hadError()) {
+ console.log('Compilation failed.');
+ return false;
+ }
+
+ console.log('Compilation successful');
+
+ results.keys().forEach(function(file) {
+ var tree = results.get(file);
+ var filename = file.name;
+ var result = traceur.codegeneration.ParseTreeWriter.write(tree, false);
+ result = runtimestub + result;
+ // Compute the output path
+ var filedir = fs.realpathSync(path.dirname(filename));
+ filedir = removeCommonPrefix(outputdir, filedir);
+ var outdir = path.join(outputdir, filedir);
+
+ mkdirRecursive(outdir);
+ var outputfile = path.join(outdir, path.basename(filename));
+ fs.writeFileSync(outputfile, new Buffer(result));
+ console.log('Writing of ' + outputfile + ' successful.');
+ });
+
+ return true;
+ }
+ var files = [];
+ function getFileNames(dir) {
+ fs.readdirSync(dir).forEach(function(file) {
+ var full = dir + '/' + file;
+ if (fs.statSync(full).isDirectory()) {
+ getFileNames(full);
+ } else if (path.extname(file) == '.js') {
+ files.push(full);
+ }
+ });
+ }
+ getFileNames(process.argv[2]);
+
+ var outdir = path.resolve(process.cwd(), process.argv[3]);
+ mkdirRecursive(outdir);
+ var outputdir = fs.realpathSync(outdir);
+ if (!compileFiles(outputdir, files)) {
+ process.exit(2);
+ } else {
+ mkdirRecursive(outputdir + '/node_modules/');
+ var runtime = fs.readFileSync(path.join(__dirname + '/../traceur/src/runtime/runtime.js')).toString();
+ // fix bug in traceur
+ runtime = runtime.replace('traceur.syntax.PredefinedName.ITERATOR','"__iterator__"');
+ // make traceur global.
+ runtime = runtime.replace('var traceur =','traceur =');
+ fs.writeFileSync(outputdir + '/node_modules/traceur-runtime.js', runtime);
+ }
+})();
View
4 examples/test.js
@@ -0,0 +1,4 @@
+require('../');
+require('./testtraceur.js');
+
+
View
26 examples/testtraceur.js
@@ -0,0 +1,26 @@
+class Foo {
+ constructor(foo = 'RAWR') {
+ console.log(foo);
+ }
+ bar(...baz) {
+ console.log('baz', ...baz)
+ }
+ static baz(bar = 3) {
+ console.log(bar);
+ }
+};
+{
+ let foo = 'bar';
+ let baz = 'baz';
+ console.log(foo, baz);
+}
+cb = (cb)-> {
+ cb(42);
+}
+cb((x) -> {
+ console.error(x * 2);
+})
+Foo.baz();
+var y = new Foo('BLAH');
+var x = new Foo();
+x.bar(1,2,3,4,5);
View
0  lib/runtime.js
No changes.
View
8 lib/traceur.js
@@ -0,0 +1,8 @@
+(function() {
+ var fs = require('fs');
+ var orig = require('module').prototype._compile;
+ var transform = require('./transform');
+ require('module').prototype._compile = function(content, filename) {
+ return orig.call(this, transform(content, filename), filename);
+ };
+})();
View
52 lib/transform.js
@@ -0,0 +1,52 @@
+var fs = require('fs'),
+ path = require('path'),
+ vm = require('vm');
+
+ function importScript(filename) {
+ filename = path.join(__dirname + '/../traceur/src', filename);
+
+ var data = fs.readFileSync(filename);
+ if (!data) {
+ throw new Error('Failed to import ' + filename);
+ }
+ data = data.toString('utf8');
+ //console.error(data);
+ vm.runInThisContext(data, filename)
+ };
+
+ global.importScript = importScript;
+ importScript('traceur.js');
+
+ //global.traceur = traceurContext.traceur;
+ var traceur = global.traceur;
+
+ // this function is silly and makes traceur unusable. so disable it.
+ traceur.semantics.FreeVariableChecker.checkProgram = function() {}
+
+
+ delete global.importScript;
+
+module.exports = function(data, filename) {
+ var reporter = new traceur.util.ErrorReporter();
+ var project = new traceur.semantics.symbols.Project();
+
+ if (!data) {
+ return false;
+ }
+ data = data.toString('utf8');
+ var sourceFile = new traceur.syntax.SourceFile(filename, data);
+ project.addFile(sourceFile);
+
+ var results = traceur.codegeneration.Compiler.compile(reporter, project);
+ if (reporter.hadError()) {
+ console.error('Compilation failed.');
+ return false;
+ }
+
+ var result = '';
+ results.keys().forEach(function(file) {
+ var tree = results.get(file);
+ result += traceur.codegeneration.ParseTreeWriter.write(tree, false);
+ });
+ return result;
+}
View
3  out/examples/test.js
@@ -0,0 +1,3 @@
+traceur = global.traceur || {};require("traceur-runtime");
+require('../');
+require('./testtraceur.js');
View
39 out/examples/testtraceur.js
@@ -0,0 +1,39 @@
+traceur = global.traceur || {};require("traceur-runtime");
+var Foo = traceur.runtime.createClass("Foo", null, null, function() {
+ var foo = arguments.length > 0 ? arguments[0]: 'RAWR';
+ console.log(foo);
+}, undefined, { bar: function() {
+ var baz = Array.prototype.slice.call(arguments, 0);
+ (function($0, $1) {
+ return $0.log.apply($0, $1);
+ })(console, traceur.runtime.spread([false, 'baz', true, baz]));
+ } }, function $static() {
+ this.baz = function() {
+ var bar = arguments.length > 0 ? arguments[0]: 3;
+ console.log(bar);
+ };
+}, null);
+;
+{
+ try {
+ throw undefined;
+ } catch(baz) {
+ try {
+ throw undefined;
+ } catch(foo) {
+ foo = 'bar';
+ baz = 'baz';
+ console.log(foo, baz);
+ }
+ }
+}
+cb = function(cb) {
+ cb(42);
+};
+cb(function(x) {
+ console.error(x * 2);
+});
+Foo.baz();
+var y = new Foo('BLAH');
+var x = new Foo();
+x.bar(1, 2, 3, 4, 5);
View
446 out/node_modules/traceur-runtime.js
@@ -0,0 +1,446 @@
+// Shim for DOM class declarations to be included before
+// including compiled classes which derive from the DOM
+
+function HTMLH1HeadingElement() {}
+function HTMLH2HeadingElement() {}
+function HTMLH3HeadingElement() {}
+function HTMLH4HeadingElement() {}
+function HTMLH5HeadingElement() {}
+function HTMLH6HeadingElement() {}
+
+try {
+ HTMLH1HeadingElement.prototype = HTMLHeadingElement.prototype;
+ HTMLH2HeadingElement.prototype = HTMLHeadingElement.prototype;
+ HTMLH3HeadingElement.prototype = HTMLHeadingElement.prototype;
+ HTMLH4HeadingElement.prototype = HTMLHeadingElement.prototype;
+ HTMLH5HeadingElement.prototype = HTMLHeadingElement.prototype;
+ HTMLH6HeadingElement.prototype = HTMLHeadingElement.prototype;
+} catch (e) {
+}
+
+
+/**
+ * The traceur runtime.
+ */
+traceur = traceur || {};
+traceur.runtime = (function() {
+ 'use strict';
+ var defineProperty = Object.defineProperty;
+ var bind = Function.prototype.bind;
+ var map = Object.create(null);
+
+ // Associates the instance maker with the class.
+ // Used below for classes inherited from DOM elements.
+ function add(name, cls, make) {
+ defineProperty(make, '$class', {value: cls});
+ // Firefox does not treat DOM constructors as functions so they do not have
+ // a name property.
+ if (!cls.name) {
+ defineProperty(cls, 'name', {value: name});
+ }
+ map[name] = make;
+ }
+
+ // AUTO-GENERATED
+ try {add('Array', Array, function() {return new Array();});}catch (e) {}
+ try {add('Date', Date, function() {return new Date();});}catch (e) {}
+ try {add('Event', Event, function() {return document.createEvent('Event');});}catch (e) {}
+ try {add('HTMLAnchorElement', HTMLAnchorElement, function() {return document.createElement('a');});}catch (e) {}
+ try {add('HTMLAreaElement', HTMLAreaElement, function() {return document.createElement('area');});}catch (e) {}
+ try {add('HTMLAudioElement', HTMLAudioElement, function() {return document.createElement('audio');});}catch (e) {}
+ try {add('HTMLBRElement', HTMLBRElement, function() {return document.createElement('br');});}catch (e) {}
+ try {add('HTMLBaseElement', HTMLBaseElement, function() {return document.createElement('base');});}catch (e) {}
+ try {add('HTMLBlockquoteElement', HTMLBlockquoteElement, function() {return document.createElement('blockquote');});}catch (e) {}
+ try {add('HTMLBodyElement', HTMLBodyElement, function() {return document.createElement('body');});}catch (e) {}
+ try {add('HTMLButtonElement', HTMLButtonElement, function() {return document.createElement('button');});}catch (e) {}
+ try {add('HTMLCanvasElement', HTMLCanvasElement, function() {return document.createElement('canvas');});}catch (e) {}
+ try {add('HTMLDListElement', HTMLDListElement, function() {return document.createElement('dl');});}catch (e) {}
+ try {add('HTMLDivElement', HTMLDivElement, function() {return document.createElement('div');});}catch (e) {}
+ try {
+ try {
+ // Feature test for native Component Model subclassing.
+ HTMLElement.call = Function.prototype.call;
+ HTMLElement.apply = Function.prototype.apply;
+ new HTMLElement();
+ }catch(featureTestException) {
+ // Else, hack in "generic" element support for constructing HTMLElement.
+ add('HTMLElement', HTMLElement, function() {return document.createElement('span');});
+ }
+ }catch (e) {}
+ try {add('HTMLEmbedElement', HTMLEmbedElement, function() {return document.createElement('embed');});}catch (e) {}
+ try {add('HTMLFieldSetElement', HTMLFieldSetElement, function() {return document.createElement('fieldset');});}catch (e) {}
+ try {add('HTMLFormElement', HTMLFormElement, function() {return document.createElement('form');});}catch (e) {}
+ try {add('HTMLH1HeadingElement', HTMLH1HeadingElement, function() {return document.createElement('h1');});}catch (e) {}
+ try {add('HTMLH2HeadingElement', HTMLH2HeadingElement, function() {return document.createElement('h2');});}catch (e) {}
+ try {add('HTMLH3HeadingElement', HTMLH3HeadingElement, function() {return document.createElement('h3');});}catch (e) {}
+ try {add('HTMLH4HeadingElement', HTMLH4HeadingElement, function() {return document.createElement('h4');});}catch (e) {}
+ try {add('HTMLH5HeadingElement', HTMLH5HeadingElement, function() {return document.createElement('h5');});}catch (e) {}
+ try {add('HTMLH6HeadingElement', HTMLH6HeadingElement, function() {return document.createElement('h6');});}catch (e) {}
+ try {add('HTMLHRElement', HTMLHRElement, function() {return document.createElement('hr');});}catch (e) {}
+ try {add('HTMLHeadElement', HTMLHeadElement, function() {return document.createElement('head');});}catch (e) {}
+ try {add('HTMLHeadingElement', HTMLHeadingElement, function() {return document.createElement('h1');});}catch (e) {}
+ try {add('HTMLHtmlElement', HTMLHtmlElement, function() {return document.createElement('html');});}catch (e) {}
+ try {add('HTMLIFrameElement', HTMLIFrameElement, function() {return document.createElement('iframe');});}catch (e) {}
+ try {add('HTMLImageElement', HTMLImageElement, function() {return document.createElement('img');});}catch (e) {}
+ try {add('HTMLInputElement', HTMLInputElement, function() {return document.createElement('input');});}catch (e) {}
+ try {add('HTMLLIElement', HTMLLIElement, function() {return document.createElement('li');});}catch (e) {}
+ try {add('HTMLLabelElement', HTMLLabelElement, function() {return document.createElement('label');});}catch (e) {}
+ try {add('HTMLLegendElement', HTMLLegendElement, function() {return document.createElement('legend');});}catch (e) {}
+ try {add('HTMLLinkElement', HTMLLinkElement, function() {return document.createElement('link');});}catch (e) {}
+ try {add('HTMLMapElement', HTMLMapElement, function() {return document.createElement('map');});}catch (e) {}
+ try {add('HTMLMenuElement', HTMLMenuElement, function() {return document.createElement('menu');});}catch (e) {}
+ try {add('HTMLMetaElement', HTMLMetaElement, function() {return document.createElement('meta');});}catch (e) {}
+ try {add('HTMLMeterElement', HTMLMeterElement, function() {return document.createElement('meter');});}catch (e) {}
+ try {add('HTMLModElement', HTMLModElement, function() {return document.createElement('del');});}catch (e) {}
+ try {add('HTMLOListElement', HTMLOListElement, function() {return document.createElement('ol');});}catch (e) {}
+ try {add('HTMLObjectElement', HTMLObjectElement, function() {return document.createElement('object');});}catch (e) {}
+ try {add('HTMLOptGroupElement', HTMLOptGroupElement, function() {return document.createElement('optgroup');});}catch (e) {}
+ try {add('HTMLOptionElement', HTMLOptionElement, function() {return document.createElement('option');});}catch (e) {}
+ try {add('HTMLOutputElement', HTMLOutputElement, function() {return document.createElement('output');});}catch (e) {}
+ try {add('HTMLParagraphElement', HTMLParagraphElement, function() {return document.createElement('p');});}catch (e) {}
+ try {add('HTMLParamElement', HTMLParamElement, function() {return document.createElement('param');});}catch (e) {}
+ try {add('HTMLPreElement', HTMLPreElement, function() {return document.createElement('pre');});}catch (e) {}
+ try {add('HTMLProgressElement', HTMLProgressElement, function() {return document.createElement('progress');});}catch (e) {}
+ try {add('HTMLQuoteElement', HTMLQuoteElement, function() {return document.createElement('q');});}catch (e) {}
+ try {add('HTMLScriptElement', HTMLScriptElement, function() {return document.createElement('script');});}catch (e) {}
+ try {add('HTMLSelectElement', HTMLSelectElement, function() {return document.createElement('select');});}catch (e) {}
+ try {add('HTMLSourceElement', HTMLSourceElement, function() {return document.createElement('source');});}catch (e) {}
+ try {add('HTMLStyleElement', HTMLStyleElement, function() {return document.createElement('style');});}catch (e) {}
+ try {add('HTMLTableCaptionElement', HTMLTableCaptionElement, function() {return document.createElement('caption');});}catch (e) {}
+ try {add('HTMLTableCellElement', HTMLTableCellElement, function() {return document.createElement('td');});}catch (e) {}
+ try {add('HTMLTableColElement', HTMLTableColElement, function() {return document.createElement('col');});}catch (e) {}
+ try {add('HTMLTableElement', HTMLTableElement, function() {return document.createElement('table');});}catch (e) {}
+ try {add('HTMLTableRowElement', HTMLTableRowElement, function() {return document.createElement('tr');});}catch (e) {}
+ try {add('HTMLTableSectionElement', HTMLTableSectionElement, function() {return document.createElement('tbody');});}catch (e) {}
+ try {add('HTMLTextAreaElement', HTMLTextAreaElement, function() {return document.createElement('textarea');});}catch (e) {}
+ try {add('HTMLTitleElement', HTMLTitleElement, function() {return document.createElement('title');});}catch (e) {}
+ try {add('HTMLUListElement', HTMLUListElement, function() {return document.createElement('ul');});}catch (e) {}
+ try {add('HTMLVideoElement', HTMLVideoElement, function() {return document.createElement('video');});}catch (e) {}
+ try {add('KeyboardEvent', KeyboardEvent, function() {return document.createEvent('KeyboardEvent');});}catch (e) {}
+ try {add('MouseEvent', MouseEvent, function() {return document.createEvent('MouseEvents');});}catch (e) {}
+ try {add('MutationEvent', MutationEvent, function() {return document.createEvent('MutationEvents');});}catch (e) {}
+ try {add('RegExp', RegExp, function() {return new RegExp();});}catch (e) {}
+ try {add('SVGZoomEvent', SVGZoomEvent, function() {return document.createEvent('SVGZoomEvents');});}catch (e) {}
+ try {add('String', String, function() {return new String();});}catch (e) {}
+ try {add('Text', Text, function() {return document.createTextNode('');});}catch (e) {}
+ try {add('TextEvent', TextEvent, function() {return document.createEvent('TextEvent');});}catch (e) {}
+ try {add('UIEvent', UIEvent, function() {return document.createEvent('UIEvents');});}catch (e) {}
+ // END AUTO-GENERATED
+
+ /**
+ * Combines mixins with the current class, issuing errors for conflicts or
+ * missing requires.
+ *
+ * @param {Object} proto the prototype for the class we're creating.
+ * @param {Array.<Object>} mixins the set of traits to mix in.
+ * @return {Object} the trait to set into new instances with defineProperties.
+ */
+ function analyzeMixins(proto, mixins) {
+ var trait = traceur.runtime.trait;
+ mixins = trait.compose.apply(null, mixins);
+ var properties = {};
+ Object.getOwnPropertyNames(mixins).forEach(function(name) {
+ var pd = mixins[name];
+ // check for remaining 'required' properties
+ // Note: it's OK for the prototype to provide the properties
+ if (pd.required) {
+ if (!(name in proto)) {
+ throw new TypeError('Missing required property: ' + name);
+ }
+ } else if (pd.conflict) { // check for remaining conflicting properties
+ throw new TypeError('Remaining conflicting property: ' + name);
+ } else {
+ properties[name] = pd;
+ }
+ });
+ return properties;
+ }
+
+ // The createClass function
+ // name: the class name
+ // base: the base class
+ // make: the function to create instance of the class
+ // i.e. function() { return document.createElement('div'); }
+ // ctor: the constructor function
+ // proto: the prototype object (containing instance methods, properties)
+ // initS: the function to initialize class static members
+ // mixins: Traits to mixin to this class
+ function createClass(name, base, make, ctor, init, proto, initS, mixins) {
+ if (base) {
+ if (typeof base != 'function' && typeof base.prototype != 'object') {
+ throw new TypeError(
+ 'Base class of ' + name +
+ ' must be a function (' + typeof base + ')');
+ }
+ } else {
+ base = Object;
+ }
+ make = make || base.$new;
+
+ if (!make && base.name) {
+ var dom = map[base.name];
+ if (dom && dom.$class === base) {
+ make = dom;
+ }
+ }
+
+ var binit = base.$init;
+ var finit = binit ?
+ (init ? function() { binit.call(this); init.call(this); } : binit) :
+ init;
+ if (ctor) {
+ defineProperty(proto, 'constructor', {
+ value: ctor,
+ enumerable: false,
+ configurable: true,
+ writable: true
+ });
+ } else {
+ ctor = proto.constructor;
+ }
+
+ proto.__proto__ = base.prototype;
+
+ if (mixins) {
+ mixins = analyzeMixins(proto, mixins);
+ }
+
+ function TheClass() {
+ var $this = make ? make() : this;
+ $this.__proto__ = TheClass.prototype;
+ if (mixins) { Object.defineProperties($this, mixins); }
+ if (finit) { finit.call($this); }
+ if (ctor) { ctor.apply($this, arguments); }
+ return $this;
+ }
+
+ TheClass.prototype = proto;
+
+ if (finit) {
+ // TODO(arv): Remove?
+ defineProperty(TheClass, '$init', {value: finit});
+ }
+ if (make) {
+ // TODO(arv): Remove?
+ defineProperty(TheClass, '$new', {value: make});
+ }
+ if (initS) { initS.call(TheClass); }
+ return TheClass;
+ }
+
+ function createTrait(parts, mixins) {
+ var trait = traceur.runtime.trait;
+ parts = trait(parts);
+ if (mixins) {
+ parts = trait.override(parts, trait.compose.apply(null, mixins));
+ }
+ return parts;
+ }
+
+ function superCall($class, name, args) {
+ var proto = Object.getPrototypeOf($class.prototype);
+ while (proto) {
+ var p = Object.getOwnPropertyDescriptor(proto, name);
+ if (p) {
+ if (p.hasOwnProperty('value')) {
+ return p.value.apply(this, args);
+ }
+ if (p.hasOwnProperty('get')) {
+ return p.get.apply(this, args);
+ }
+ }
+ proto = Object.getPrototypeOf(proto);
+ }
+ throw new TypeError("Object has no method '" + name + "'.");
+ }
+
+ function superGet($class, name) {
+ var proto = Object.getPrototypeOf($class.prototype);
+ while (proto) {
+ var p = Object.getOwnPropertyDescriptor(proto, name);
+ if (p) {
+ if (p.hasOwnProperty('value')) {
+ return p.value;
+ }
+ if (p.hasOwnProperty('get')) {
+ return p.get.call(this);
+ }
+ }
+ proto = Object.getPrototypeOf(proto);
+ }
+ return undefined;
+ }
+
+ // Add iterator support to arrays.
+ defineProperty(Array.prototype, "__iterator__", {
+ value: function() {
+ var index = 0;
+ var array = this;
+ var current;
+ return {
+ get current() {
+ return current;
+ },
+ moveNext: function() {
+ if (index < array.length) {
+ current = array[index++];
+ return true;
+ }
+ return false;
+ }
+ };
+ },
+ enumerable: false,
+ configurable: true,
+ writable: true
+ });
+
+ var pushItem = Array.prototype.push.call.bind(Array.prototype.push);
+ var pushArray = Array.prototype.push.apply.bind(Array.prototype.push);
+ var slice = Array.prototype.slice.call.bind(Array.prototype.slice);
+
+ /**
+ * Spreads the elements in {@code items} into a single array.
+ * @param {Array} items Array of interleaving booleans and values.
+ * @return {Array}
+ */
+ function spread(items) {
+ var retval = [];
+ for (var i = 0; i < items.length; i += 2) {
+ if (items[i]) {
+ if (items[i + 1] == null)
+ continue;
+ if (typeof items[i + 1] != 'object')
+ throw TypeError('Spread expression has wrong type');
+ pushArray(retval, slice(items[i + 1]));
+ } else {
+ pushItem(retval, items[i + 1]);
+ }
+ }
+ return retval;
+ }
+
+ /**
+ * @param {Function} ctor
+ * @param {Array} items Array of interleaving booleans and values.
+ * @return {Object}
+ */
+ function spreadNew(ctor, items) {
+ var args = spread(items);
+ args.unshift(null);
+ var retval = new (bind.apply(ctor, args));
+ return retval && typeof retval == 'object' ? retval : object;
+ };
+
+ /**
+ * Marks properties as non enumerable.
+ * @param {Object} object
+ * @param {Array.<string>} names
+ * @return {Object}
+ */
+ function markMethods(object, names) {
+ names.forEach(function(name) {
+ Object.defineProperty(object, name, {enumerable: false});
+ });
+ return object;
+ }
+
+ /**
+ * @param {Function} canceller
+ * @constructor
+ */
+ function Deferred(canceller) {
+ this.canceller_ = canceller;
+ this.listeners_ = [];
+ }
+
+ function notify(self) {
+ while (self.listeners_.length > 0) {
+ var current = self.listeners_.shift();
+ var currentResult = undefined;
+ try {
+ try {
+ if (self.result_[1]) {
+ if (current.errback)
+ currentResult = current.errback.call(undefined, self.result_[0]);
+ } else {
+ if (current.callback)
+ currentResult = current.callback.call(undefined, self.result_[0]);
+ }
+ current.deferred.callback(currentResult);
+ } catch (err) {
+ current.deferred.errback(err);
+ }
+ } catch (unused) {}
+ }
+ }
+
+ function fire(self, value, isError) {
+ if (self.fired_)
+ throw new Error('already fired');
+
+ self.fired_ = true;
+ self.result_ = [value, isError];
+ notify(self);
+ }
+
+ Deferred.prototype = {
+ fired_: false,
+ result_: undefined,
+
+ createPromise: function() {
+ return {then: this.then.bind(this), cancel: this.cancel.bind(this)};
+ },
+
+ callback: function(value) {
+ fire(this, value, false);
+ },
+
+ errback: function(err) {
+ fire(this, err, true);
+ },
+
+ then: function(callback, errback) {
+ var result = new Deferred(this.cancel.bind(this));
+ this.listeners_.push({
+ deferred: result,
+ callback: callback,
+ errback: errback
+ });
+ if (this.fired_)
+ notify(this);
+ return result.createPromise();
+ },
+
+ cancel: function() {
+ if (this.fired_)
+ throw new Error('already finished');
+ var result;
+ if (this.canceller_) {
+ result = this.canceller_(this);
+ if (!result instanceof Error)
+ result = new Error(result);
+ } else {
+ result = new Error('cancelled');
+ }
+ if (!this.fired_) {
+ this.result_ = [result, true];
+ notify(this);
+ }
+ }
+ };
+
+ // Return the traceur namespace.
+ return {
+ createClass: createClass,
+ createTrait: createTrait,
+ Deferred: Deferred,
+ markMethods: markMethods,
+ spread: spread,
+ spreadNew: spreadNew,
+ superCall: superCall,
+ superGet: superGet
+ };
+})();
+
+var Deferred = traceur.runtime.Deferred;
View
12 package.json
@@ -1,23 +1,21 @@
{
"name": "traceur",
"description": "Traceur compiler for node.js",
- "version": "1.1.1",
+ "version": "2.0.0",
"homepage": "http://aikar.co/traceur",
"repository": {
"type": "git",
"url": "git@github.com:aikar/traceur"
},
"author": "Aikar <aikar@aikar.co>",
- "main": "traceur.js",
- "devDependencies": {
- "vows": ""
- },
+ "main": "lib/traceur.js",
"bugs": {
"mail": "aikar@aikar.co",
"web": "https://github.com/aikar/traceur/issues"
},
- "scripts": {
- "test": "./runTest.js"
+ "bin" : {
+ "traceur":"./bin/traceur",
+ "traceurc":"./bin/traceurc"
},
"engines": {
"node": ">=0.4.0"
View
5 test.js
@@ -1,5 +0,0 @@
-require('./traceur');
-foo = require('./testtraceur.js');
-
-var x = new foo();
-x.bar();
View
20 testtraceur.js
@@ -1,20 +0,0 @@
-class Foo {
- new() {
- console.log('RAWR');
- }
- bar() {
- console.log('baz')
- }
-};
-{
- let foo = 'bar';
- console.log(foo);
-}
-cb = (cb)-> {
- cb(42);
-}
-cb((x) -> {
- console.error(x * 2);
-})
-console.log(typeof foo);
-module.exports = Foo
View
64 traceur.js
@@ -1,64 +0,0 @@
-
-(function() {
- var
- fs = require('fs'),
- path = require('path'),
- vm = require('vm');
- function importScript(filename) {
- filename = path.join(__dirname + '/traceur/src', filename);
-
- var data = fs.readFileSync(filename);
- if (!data) {
- throw new Error('Failed to import ' + filename);
- }
- data = data.toString('utf8');
- //console.error(data);
- vm.runInThisContext(data, filename)
- };
-
- global.importScript = importScript;
- importScript('traceur.js');
-
- //global.traceur = traceurContext.traceur;
- var traceur = global.traceur;
-
- // this function is silly and makes traceur unusable. so disable it.
- traceur.semantics.FreeVariableChecker.checkProgram = function() {}
-
-
- delete global.importScript;
-
- var orig = require.extensions['.js'];
- require.extensions['.js'] = function(module, filename) {
- var reporter = new traceur.util.ErrorReporter();
- var project = new traceur.semantics.symbols.Project();
-
- //console.error('Reading file...', filename);
-
- var data = fs.readFileSync(filename);
- if (!data) {
- //console.error('Failed to read ' + filename);
- return false;
- }
- data = data.toString('utf8');
- var sourceFile = new traceur.syntax.SourceFile(filename, data);
- project.addFile(sourceFile);
-
- //console.error('Compiling...');
- var results = traceur.codegeneration.Compiler.compile(reporter, project);
- if (reporter.hadError()) {
- console.error('Compilation failed.');
- return false;
- }
-
- //console.error('Compilation successful');
- var result = '';
- results.keys().forEach(function(file) {
- var tree = results.get(file);
- result += traceur.codegeneration.ParseTreeWriter.write(tree, false);
- });
- //console.error(result);
- module._compile(result, filename);
- return true;
- };
-})();
View
14 traceur/demo/generators.js
@@ -73,11 +73,11 @@ function tree(list) {
// A recursive generator that generates Tree labels in in-order.
function inorder1(t) {
if (t) {
- for (var x : inorder1(t.left)) {
+ for (var x of inorder1(t.left)) {
yield x;
}
yield t.label;
- for (var x : inorder1(t.right)) {
+ for (var x of inorder1(t.right)) {
yield x;
}
}
@@ -87,7 +87,7 @@ function inorder1(t) {
var root = tree('ABCDEFGHIJKLMNOPQRSTUVWXYZ');
// Print the nodes of the tree in in-order.
var result = '';
-for (let x : inorder1(root)) {
+for (let x of inorder1(root)) {
result += x;
}
alert(result);
@@ -111,7 +111,7 @@ function inorder2(node) {
// Exercise the non-recursive generator.
var result = '';
-for (var x : inorder2(root)) {
+for (var x of inorder2(root)) {
result += x;
}
alert(result);
@@ -120,12 +120,12 @@ alert(result);
// These can be combined without creating intermediate arrays
function map(list, fun) {
- for (var item : list) {
+ for (var item of list) {
yield fun(item);
}
}
function filter(list, fun) {
- for (var item : list) {
+ for (var item of list) {
if (fun(item)) {
yield item;
}
@@ -139,7 +139,7 @@ var squares = map(
function(x) { return x * x; });
numbers = [];
-for (let s : squares) {
+for (let s of squares) {
numbers.push(s);
}
alert(numbers.join('_'));
View
3  traceur/demo/repl.html
@@ -79,7 +79,8 @@
errorElement.textContent += format + '\n';
};
- var project = new traceur.semantics.symbols.Project();
+ var url = window.location.href;
+ var project = new traceur.semantics.symbols.Project(url);
var name = 'repl';
var contents = input.value;
var sourceFile = new traceur.syntax.SourceFile(name, contents);
View
28 traceur/presentation/index.html
@@ -309,13 +309,13 @@
</h3>
<pre data-part='1'>
class Actor {
- new() { ... }
- moveTo: function (pos) { ... }
+ constructor() { ... }
+ moveTo(pos) { ... }
}
-class PacMan : Actor {
- new() { ... }
- eat: function() { ... }
+class PacMan extends Actor {
+ constructor() { ... }
+ eat() { ... }
}
</pre>
</div>
@@ -628,7 +628,7 @@
/* Positions of energizers (big dots that allow Pac-Man to eat ghosts). */
var PM_ENERGIZERS = [ ... ];
-for (var energizer: PM_ENERGIZERS) {
+for (var energizer of PM_ENERGIZERS) {
...
}
</pre>
@@ -678,7 +678,7 @@
return { getIterator: iterator };
}
-for (var i: fib(10)) { print(i); }
+for (var i of fib(10)) { print(i); }
</pre>
</div>
</div>
@@ -705,7 +705,7 @@
}
return result;
}
-for (var node: allNodes(document)) {
+for (var node of allNodes(document)) {
...
}
</pre>
@@ -758,11 +758,11 @@
<pre>
function allNodes(node) {
// ?? return node
- for (var child : node.childNodes || [])
+ for (var child of node.childNodes || [])
// ?? return each of allNodes(child);
}
-for (var node: allNodes(document)) {
+for (var node of allNodes(document)) {
...
}
</pre>
@@ -837,11 +837,11 @@
<pre>
function allNodes(node) {
// ?? return node
- for (var child : node.childNodes || [])
+ for (var child of node.childNodes || [])
// ?? return each of allNodes(child);
}
-for (var node: allNodes(document)) {
+for (var node of allNodes(document)) {
...
}
</pre>
@@ -859,11 +859,11 @@
<pre>
function allNodes(node) {
yield node;
- for (var child : node.childNodes || [])
+ for (var child of node.childNodes || [])
yield for allNodes(child);
}
-for (var node: allNodes(document)) {
+for (var node of allNodes(document)) {
...
}
</pre>
View
3  traceur/presentation/script.js
@@ -390,7 +390,8 @@ function initializeTraceurSlide() {
error = error ? error + e : e;
};
- var project = new traceur.semantics.symbols.Project();
+ var url = window.location.href;
+ var project = new traceur.semantics.symbols.Project(url);
var name = 'traceur';
var contents = input.value;
var sourceFile = new traceur.syntax.SourceFile(name, contents);
View
10 traceur/src/codegeneration/ClassTransformer.js
@@ -48,7 +48,7 @@ traceur.define('codegeneration', function() {
var createMemberExpression = ParseTreeFactory.createMemberExpression;
var createNullLiteral = ParseTreeFactory.createNullLiteral;
var createObjectLiteralExpression = ParseTreeFactory.createObjectLiteralExpression;
- var createParameters = ParseTreeFactory.createParameters;
+ var createParameterList = ParseTreeFactory.createParameterList;
var createPropertyNameAssignment = ParseTreeFactory.createPropertyNameAssignment;
var createSetAccessor = ParseTreeFactory.createSetAccessor;
var createStringLiteral = ParseTreeFactory.createStringLiteral;
@@ -283,7 +283,7 @@ traceur.define('codegeneration', function() {
fields.push(createPropertyNameAssignment(PredefinedName.SET,
this.transformStaticMethod_(
aggregate,
- createParameters(set.tree.parameter),
+ createParameterList(set.tree.parameter),
set.tree.body)));
}
@@ -306,13 +306,13 @@ traceur.define('codegeneration', function() {
createMemberExpression(classInstance, method.name),
this.transformStaticMethod_(
method.containingAggregate,
- createParameters(method.tree.formalParameterList),
+ method.tree.formalParameterList,
method.tree.functionBody));
},
/**
* @param {AggregateSymbol} aggregate
- * @param {Array.<string>} formalParameters
+ * @param {FormalParameterList} formalParameters
* @param {Block} functionBody
* @return {FunctionDeclaration}
*/
@@ -461,7 +461,7 @@ traceur.define('codegeneration', function() {
var methodTree = method.tree;
return this.transformStaticMethod_(
sym,
- createParameters(methodTree.formalParameterList),
+ methodTree.formalParameterList,
methodTree.functionBody);
}
},
View
77 traceur/src/codegeneration/DestructuringTransformer.js
@@ -19,6 +19,7 @@ traceur.define('codegeneration', function() {
var ParseTreeFactory = traceur.codegeneration.ParseTreeFactory;
var AlphaRenamer = traceur.codegeneration.AlphaRenamer;
+ var ParseTreeVisitor = traceur.syntax.ParseTreeVisitor;
var PredefinedName = traceur.syntax.PredefinedName;
var TokenType = traceur.syntax.TokenType;
var ParseTreeType = traceur.syntax.trees.ParseTreeType;
@@ -95,6 +96,48 @@ traceur.define('codegeneration', function() {
});
/**
+ * This is used to see if a function body contains a reference to arguments.
+ * Does not search into nested functions.
+ * @param {ParseTree} tree
+ * @extends {ParseTreeVisitor}
+ * @constructor
+ */
+ function ArgumentsFinder(tree) {
+ try {
+ this.visitAny(tree);
+ } catch (ex) {
+ // This uses an exception to do early exits.
+ if (ex !== foundSentinel) {
+ throw ex;
+ }
+ }
+ }
+
+ // Object used as a sentinel. This is thrown to abort visiting the rest of the
+ // tree.
+ var foundSentinel = {};
+
+ ArgumentsFinder.prototype = traceur.createObject(ParseTreeVisitor.prototype, {
+ hasArguments: false,
+
+ /**
+ * @param {IdentifierExpression} tree
+ */
+ visitIdentifierExpression: function(tree) {
+ if (tree.identifierToken.value === PredefinedName.ARGUMENTS) {
+ this.hasArguments = true;
+ // Exit early.
+ throw foundSentinel;
+ }
+ },
+
+ // don't visit function children or bodies
+ visitFunctionDeclaration: function(tree) {},
+ visitSetAccessor: function(tree) {},
+ visitGetAccessor: function(tree) {}
+ });
+
+ /**
* Desugars destructuring assignment.
*
* @see <a href="http://wiki.ecmascript.org/doku.php?id=harmony:destructuring#assignments">harmony:destructuring</a>
@@ -166,20 +209,36 @@ traceur.define('codegeneration', function() {
this.desugarPattern_(desugaring, lvalue);
desugaring.statements.push(createReturnStatement(desugaring.rvalue));
+ var finder = new ArgumentsFinder(lvalue);
+ if (finder.hasArguments) {
+ // function($0, $arguments) { alpha renamed body }
+ var func = createFunctionExpression(
+ createParameterList(
+ PredefinedName.getParameterName(0),
+ PredefinedName.CAPTURED_ARGUMENTS),
+ AlphaRenamer.rename(
+ createBlock(desugaring.statements),
+ PredefinedName.ARGUMENTS,
+ PredefinedName.CAPTURED_ARGUMENTS));
+
+ // (func).call(this, rvalue, arguments)
+ return createCallCall(
+ createParenExpression(func),
+ createThisExpression(),
+ rvalue,
+ createIdentifierExpression(PredefinedName.ARGUMENTS));
+ }
+
+ // function($0) { body }
var func = createFunctionExpression(
- createParameterList(
- PredefinedName.getParameterName(0),
- PredefinedName.CAPTURED_ARGUMENTS),
- AlphaRenamer.rename(
- createBlock(desugaring.statements),
- PredefinedName.ARGUMENTS,
- PredefinedName.CAPTURED_ARGUMENTS));
+ createParameterList(PredefinedName.getParameterName(0)),
+ createBlock(desugaring.statements));
+ // (func).call(this, rvalue)
return createCallCall(
createParenExpression(func),
createThisExpression(),
- rvalue,
- createIdentifierExpression(PredefinedName.ARGUMENTS));
+ rvalue);
},
/**
View
22 traceur/src/codegeneration/ForEachTransformer.js → traceur/src/codegeneration/ForOfTransformer.js
@@ -33,11 +33,11 @@ traceur.define('codegeneration', function() {
var createWhileStatement = ParseTreeFactory.createWhileStatement;
/**
- * Desugars foreach statement.
+ * Desugars for of statement.
* @param {UniqueIdentifierGenerator} identifierGenerator
* @constructor
*/
- function ForEachTransformer(identifierGenerator) {
+ function ForOfTransformer(identifierGenerator) {
ParseTreeTransformer.call(this);
this.identifierGenerator_ = identifierGenerator;
Object.freeze(this);
@@ -47,14 +47,14 @@ traceur.define('codegeneration', function() {
* @param {UniqueIdentifierGenerator} identifierGenerator
* @param {ParseTree} tree
*/
- ForEachTransformer.transformTree = function(identifierGenerator, tree) {
- return new ForEachTransformer(identifierGenerator).transformAny(tree);
+ ForOfTransformer.transformTree = function(identifierGenerator, tree) {
+ return new ForOfTransformer(identifierGenerator).transformAny(tree);
};
- ForEachTransformer.prototype = traceur.createObject(
+ ForOfTransformer.prototype = traceur.createObject(
ParseTreeTransformer.prototype, {
- // for ( initializer : collection ) statement
+ // for ( initializer of collection ) statement
//
// let $it = collection.__traceurIterator__();
// try {
@@ -67,15 +67,15 @@ traceur.define('codegeneration', function() {
// $it.close();
// }
/**
- * @param {ForEachStatement} original
+ * @param {ForOfStatement} original
* @return {ParseTree}
*/
- transformForEachStatement: function(original) {
- var tree = ParseTreeTransformer.prototype.transformForEachStatement.call(
+ transformForOfStatement: function(original) {
+ var tree = ParseTreeTransformer.prototype.transformForOfStatement.call(
this, original);
// let $it = collection.__traceurIterator__();
- // TODO: use 'var' instead of 'let' to enable yield's from within foreach statements
+ // TODO: use 'var' instead of 'let' to enable yield's from within for of statements
var iter = this.identifierGenerator_.generateUniqueIdentifier();
var initializer = createVariableStatement(TokenType.VAR, iter,
createCallExpression(createMemberExpression(tree.collection, PredefinedName.ITERATOR)));
@@ -107,6 +107,6 @@ traceur.define('codegeneration', function() {
});
return {
- ForEachTransformer: ForEachTransformer
+ ForOfTransformer: ForOfTransformer
};
});
View
14 traceur/src/codegeneration/GeneratorTransformPass.js
@@ -21,13 +21,13 @@ traceur.define('codegeneration', function() {
var SetAccessor = traceur.syntax.trees.SetAccessor;
var ParseTreeTransformer = traceur.codegeneration.ParseTreeTransformer;
- var ForEachTransformer = traceur.codegeneration.ForEachTransformer;
+ var ForOfTransformer = traceur.codegeneration.ForOfTransformer;
var ForInTransformPass = traceur.codegeneration.generator.ForInTransformPass;
var GeneratorTransformer = traceur.codegeneration.generator.GeneratorTransformer;
var AsyncTransformer = traceur.codegeneration.generator.AsyncTransformer;
- var createForEachStatement = traceur.codegeneration.ParseTreeFactory.createForEachStatement;
+ var createForOfStatement = traceur.codegeneration.ParseTreeFactory.createForOfStatement;
var createVariableDeclarationList = traceur.codegeneration.ParseTreeFactory.createVariableDeclarationList;
var createYieldStatement = traceur.codegeneration.ParseTreeFactory.createYieldStatement;
var createIdentifierExpression = traceur.codegeneration.ParseTreeFactory.createIdentifierExpression;
@@ -81,8 +81,8 @@ traceur.define('codegeneration', function() {
});
/**
- * This transformer turns "yield for E" into a ForEach that
- * contains a yield and is lowered by the ForEachTransformer.
+ * This transformer turns "yield for E" into a ForOf that
+ * contains a yield and is lowered by the ForOfTransformer.
*/
function YieldForTransformer(identifierGenerator) {
ParseTreeTransformer.call(this);
@@ -100,11 +100,11 @@ traceur.define('codegeneration', function() {
if (tree.isYieldFor) {
// yield for E
// becomes
- // for (var $TEMP : E) { yield $TEMP; }
+ // for (var $TEMP of E) { yield $TEMP; }
var id = createIdentifierExpression(this.identifierGenerator_.generateUniqueIdentifier());
- var forEach = createForEachStatement(
+ var forEach = createForOfStatement(
createVariableDeclarationList(
TokenType.VAR,
id,
@@ -113,7 +113,7 @@ traceur.define('codegeneration', function() {
tree.expression,
createYieldStatement(id, false /* isYieldFor */));
- var result = ForEachTransformer.transformTree(
+ var result = ForOfTransformer.transformTree(
this.identifierGenerator_,
forEach);
View
31 traceur/src/codegeneration/ParseTreeFactory.js
@@ -45,7 +45,7 @@ traceur.define('codegeneration', function() {
var ExpressionStatement = traceur.syntax.trees.ExpressionStatement;
var FieldDeclaration = traceur.syntax.trees.FieldDeclaration;
var Finally = traceur.syntax.trees.Finally;
- var ForEachStatement = traceur.syntax.trees.ForEachStatement;
+ var ForOfStatement = traceur.syntax.trees.ForOfStatement;
var ForInStatement = traceur.syntax.trees.ForInStatement;
var ForStatement = traceur.syntax.trees.ForStatement;
var FormalParameterList = traceur.syntax.trees.FormalParameterList;
@@ -143,26 +143,6 @@ traceur.define('codegeneration', function() {
}
/**
- * @param {IdentifierToken|FormalParameterList} parameter
- * @return {Array.<string>}
- */
- function createParameters(parameter) {
- if (parameter instanceof IdentifierToken)
- return [parameter.value];
-
- var builder = [];
-
- parameter.parameters.forEach(function(parameter) {
- if (!parameter.isRestParameter()) {
- // TODO: array and object patterns
- builder.push(parameter.identifierToken.value);
- }
- });
-
- return builder;
- }
-
- /**
* Either creates an array from the arguments, or if the first argument is an
* array, creates a new array with its elements followed by the other
* arguments.
@@ -606,10 +586,10 @@ traceur.define('codegeneration', function() {
* @param {VariableDeclarationList} initializer
* @param {ParseTree} collection
* @param {ParseTree} body
- * @return {ForEachStatement}
+ * @return {ForOfStatement}
*/
- function createForEachStatement(initializer, collection, body) {
- return new ForEachStatement(null, initializer, collection, body);
+ function createForOfStatement(initializer, collection, body) {
+ return new ForOfStatement(null, initializer, collection, body);
}
/**
@@ -1134,7 +1114,7 @@ traceur.define('codegeneration', function() {
createFalseLiteral: createFalseLiteral,
createFieldDeclaration: createFieldDeclaration,
createFinally: createFinally,
- createForEachStatement: createForEachStatement,
+ createForOfStatement: createForOfStatement,
createForInStatement: createForInStatement,
createForStatement: createForStatement,
createFunctionDeclaration: createFunctionDeclaration,
@@ -1162,7 +1142,6 @@ traceur.define('codegeneration', function() {
createParameterList: createParameterList,
createParameterListWithRestParams: createParameterListWithRestParams,
createParameterReference: createParameterReference,
- createParameters: createParameters,
createParenExpression: createParenExpression,
createPostfixExpression: createPostfixExpression,
createProgram: createProgram,
View
8 traceur/src/codegeneration/ParseTreeTransformer.js
@@ -34,7 +34,7 @@ traceur.define('codegeneration', function() {
var createExpressionStatement = ParseTreeFactory.createExpressionStatement;
var createFieldDeclaration = ParseTreeFactory.createFieldDeclaration;
var createFinally = ParseTreeFactory.createFinally;
- var createForEachStatement = ParseTreeFactory.createForEachStatement;
+ var createForOfStatement = ParseTreeFactory.createForOfStatement;
var createForInStatement = ParseTreeFactory.createForInStatement;
var createForStatement = ParseTreeFactory.createForStatement;
var createFunctionDeclaration = ParseTreeFactory.createFunctionDeclaration;
@@ -546,10 +546,10 @@ traceur.define('codegeneration', function() {
},
/**
- * @param {ForEachStatement} tree
+ * @param {ForOfStatement} tree
* @return {ParseTree}
*/
- transformForEachStatement: function(tree) {
+ transformForOfStatement: function(tree) {
var initializer = this.transformAny(tree.initializer);
var collection = this.transformAny(tree.collection);
var body = this.transformAny(tree.body);
@@ -557,7 +557,7 @@ traceur.define('codegeneration', function() {
body == tree.body) {
return tree;
}
- return createForEachStatement(initializer,
+ return createForOfStatement(initializer,
collection, body);
},
View
14 traceur/src/codegeneration/ParseTreeWriter.js
@@ -396,7 +396,7 @@ traceur.define('codegeneration', function() {
*/
visitFieldDeclaration: function(tree) {
if (tree.isStatic) {
- this.write_(TokenType.CLASS);
+ this.write_(TokenType.STATIC);
}
if (tree.isConst) {
this.write_(TokenType.CONST);
@@ -414,13 +414,13 @@ traceur.define('codegeneration', function() {
},
/**
- * @param {ForEachStatement} tree
+ * @param {ForOfStatement} tree
*/
- visitForEachStatement: function(tree) {
+ visitForOfStatement: function(tree) {
this.write_(TokenType.FOR);
this.write_(TokenType.OPEN_PAREN);
this.visitAny(tree.initializer);
- this.write_(TokenType.COLON);
+ this.write_(PredefinedName.OF);
this.visitAny(tree.collection);
this.write_(TokenType.CLOSE_PAREN);
this.visitAny(tree.body);
@@ -478,7 +478,7 @@ traceur.define('codegeneration', function() {
*/
visitFunctionDeclaration: function(tree) {
if (tree.isStatic) {
- this.write_(TokenType.CLASS);
+ this.write_(TokenType.STATIC);
}
this.write_(Keywords.FUNCTION);
if (tree.name != null) {
@@ -495,7 +495,7 @@ traceur.define('codegeneration', function() {
*/
visitGetAccessor: function(tree) {
if (tree.isStatic) {
- this.write_(TokenType.CLASS);
+ this.write_(TokenType.STATIC);
}
this.write_(PredefinedName.GET);
this.write_(tree.propertyName);
@@ -828,7 +828,7 @@ traceur.define('codegeneration', function() {
*/
visitSetAccessor: function(tree) {
if (tree.isStatic) {
- this.write_(TokenType.CLASS);
+ this.write_(TokenType.STATIC);
}
this.write_(PredefinedName.SET);
this.write_(tree.propertyName);
View
10 traceur/src/codegeneration/ProgramTransformer.js
@@ -20,7 +20,7 @@ traceur.define('codegeneration', function() {
var ParseTreeValidator = traceur.syntax.ParseTreeValidator;
var ProgramTree = traceur.syntax.trees.ProgramTree;
var UniqueIdentifierGenerator = traceur.codegeneration.UniqueIdentifierGenerator;
- var ForEachTransformer = traceur.codegeneration.ForEachTransformer;
+ var ForOfTransformer = traceur.codegeneration.ForOfTransformer;
var PropertyMethodAssignmentTransformer = traceur.codegeneration.PropertyMethodAssignmentTransformer;
var PropertyNameShorthandTransformer = traceur.codegeneration.PropertyNameShorthandTransformer;
var RestParameterTransformer = traceur.codegeneration.RestParameterTransformer;
@@ -159,9 +159,9 @@ traceur.define('codegeneration', function() {
chain(PropertyNameShorthandTransformer.transformTree);
chain(ClassTransformer.transform.bind(null, this.reporter_));
- // foreach must come before destructuring and generator, or anything
+ // for of must come before destructuring and generator, or anything
// that wants to use VariableBinder
- chain(ForEachTransformer.transformTree.bind(null,
+ chain(ForOfTransformer.transformTree.bind(null,
this.identifierGenerator_));
// rest parameters must come before generator
@@ -171,12 +171,12 @@ traceur.define('codegeneration', function() {
// expected order in the transformed code.
chain(DefaultParametersTransformer.transformTree);
- // generator must come after foreach and rest parameters
+ // generator must come after for of and rest parameters
chain(GeneratorTransformPass.transformTree.bind(null,
this.identifierGenerator_,
this.reporter_));
- // destructuring must come after foreach and before block binding
+ // destructuring must come after for of and before block binding
chain(DestructuringTransformer.transformTree);
chain(SpreadTransformer.transformTree);
chain(BlockBindingTransformer.transformTree);
View
6 traceur/src/codegeneration/generator/BreakContinueTransformer.js
@@ -21,7 +21,7 @@ traceur.define('codegeneration.generator', function() {
var BreakStatement = traceur.syntax.trees.BreakStatement;
var ContinueStatement = traceur.syntax.trees.ContinueStatement;
var DoWhileStatement = traceur.syntax.trees.DoWhileStatement;
- var ForEachStatement = traceur.syntax.trees.ForEachStatement;
+ var ForOfStatement = traceur.syntax.trees.ForOfStatement;
var ForStatement = traceur.syntax.trees.ForStatement;
var FunctionDeclaration = traceur.syntax.trees.FunctionDeclaration;
var ParseTree = traceur.syntax.trees.ParseTree;
@@ -111,10 +111,10 @@ traceur.define('codegeneration.generator', function() {
},
/**
- * @param {ForEachStatement} tree
+ * @param {ForOfStatement} tree
* @return {ParseTree}
*/
- transformForEachStatement: function(tree) {
+ transformForOfStatement: function(tree) {
return tree;
},
View
6 traceur/src/codegeneration/generator/CPSTransformer.js
@@ -325,11 +325,11 @@ traceur.define('codegeneration.generator', function() {
},
/**
- * @param {ForEachStatement} tree
+ * @param {ForOfStatement} tree
* @return {ParseTree}
*/
- transformForEachStatement: function(tree) {
- throw new Error('foreach statements should be transformed before this pass');
+ transformForOfStatement: function(tree) {
+ throw new Error('for of statements should be transformed before this pass');
},
/**
View
2  traceur/src/codegeneration/module/ModuleDefinitionVisitor.js
@@ -41,7 +41,7 @@ traceur.define('codegeneration.module', function() {
var name = tree.name.value;
if (this.checkForDuplicateModule_(name, tree)) {
var parent = this.currentModule;
- var module = new ModuleSymbol(name, parent, tree);
+ var module = new ModuleSymbol(name, parent, tree, parent.url);
parent.addModule(module);
}
View
2  traceur/src/filecompiler.js
@@ -78,7 +78,7 @@
function compileFiles(filenames) {
var reporter = new traceur.util.ErrorReporter();
- var project = new traceur.semantics.symbols.Project();
+ var project = new traceur.semantics.symbols.Project(process.cwd());
console.log('Reading files...');
var success = filenames.every(function(filename) {
View
22 traceur/src/runtime/runtime.js
@@ -56,7 +56,17 @@ traceur.runtime = (function() {
try {add('HTMLCanvasElement', HTMLCanvasElement, function() {return document.createElement('canvas');});}catch (e) {}
try {add('HTMLDListElement', HTMLDListElement, function() {return document.createElement('dl');});}catch (e) {}
try {add('HTMLDivElement', HTMLDivElement, function() {return document.createElement('div');});}catch (e) {}
- try {add('HTMLElement', HTMLElement, function() {return document.createElement('span');});}catch (e) {}
+ try {
+ try {
+ // Feature test for native Component Model subclassing.
+ HTMLElement.call = Function.prototype.call;
+ HTMLElement.apply = Function.prototype.apply;
+ new HTMLElement();
+ }catch(featureTestException) {
+ // Else, hack in "generic" element support for constructing HTMLElement.
+ add('HTMLElement', HTMLElement, function() {return document.createElement('span');});
+ }
+ }catch (e) {}
try {add('HTMLEmbedElement', HTMLEmbedElement, function() {return document.createElement('embed');});}catch (e) {}
try {add('HTMLFieldSetElement', HTMLFieldSetElement, function() {return document.createElement('fieldset');});}catch (e) {}
try {add('HTMLFormElement', HTMLFormElement, function() {return document.createElement('form');});}catch (e) {}
@@ -179,7 +189,12 @@ traceur.runtime = (function() {
(init ? function() { binit.call(this); init.call(this); } : binit) :
init;
if (ctor) {
- proto.constructor = ctor;
+ defineProperty(proto, 'constructor', {
+ value: ctor,
+ enumerable: false,
+ configurable: true,
+ writable: true
+ });
} else {
ctor = proto.constructor;
}
@@ -201,11 +216,12 @@ traceur.runtime = (function() {
TheClass.prototype = proto;
- defineProperty(TheClass, '$className', {value: name});
if (finit) {
+ // TODO(arv): Remove?
defineProperty(TheClass, '$init', {value: finit});
}
if (make) {
+ // TODO(arv): Remove?
defineProperty(TheClass, '$new', {value: make});
}
if (initS) { initS.call(TheClass); }
View
8 traceur/src/semantics/ClassAnalyzer.js
@@ -165,8 +165,8 @@ traceur.define('semantics', function() {
this.reportError_(tree, 'Cannot use destructuring in a field declaration');
break;
}
- if (PredefinedName.NEW == name) {
- this.reportError_(tree, 'Cannot name a field "new"');
+ if (PredefinedName.CONSTRUCTOR == name) {
+ this.reportError_(tree, 'Cannot name a field "constructor"');
return;
}
if (!this.checkForDuplicateMemberDeclaration_(aggregate, tree, name, field.isStatic)) {
@@ -236,8 +236,8 @@ traceur.define('semantics', function() {
default:
throw new Error('Unexpected property name type');
}
- if (name == PredefinedName.NEW) {
- this.reportError_(tree, 'Cannot name a property "new"');
+ if (name == PredefinedName.CONSTRUCTOR) {
+ this.reportError_(tree, 'Cannot name a property "constructor"');
return null;
}
return name;
View
2  traceur/src/semantics/FreeVariableChecker.js
@@ -32,7 +32,7 @@ traceur.define('semantics', function() {
* particular we can ignore:
* - module imports
* - block scope (let/const)
- * - foreach
+ * - for of
* - generators
* - destructuring/rest
* - classes/traits
View
6 traceur/src/semantics/VariableBinder.js
@@ -185,9 +185,9 @@ traceur.define('semantics', function() {
// their own lexical scope.
},
- /** @param {ForEachStatement} tree */
- visitForEachStatement: function(tree) {
- throw new Error('foreach statements should be transformed before this pass');
+ /** @param {ForOfStatement} tree */
+ visitForOfStatement: function(tree) {
+ throw new Error('for of statements should be transformed before this pass');
},
/** @param {ForInStatement} tree */
View
4 traceur/src/semantics/symbols/AggregateSymbol.js
@@ -189,14 +189,14 @@ traceur.define('semantics.symbols', function() {
* @return {MethodSymbol}
*/
getConstructor: function() {
- return this.getInstanceMember(PredefinedName.NEW);
+ return this.getInstanceMember(PredefinedName.CONSTRUCTOR);
},
/**
* @return {MethodSymbol}
*/
getStaticConstructor: function() {
- return this.getStaticMember(PredefinedName.NEW);
+ return this.getStaticMember(PredefinedName.CONSTRUCTOR);
},
/**
View
2  traceur/src/semantics/symbols/MethodSymbol.js
@@ -39,7 +39,7 @@ traceur.define('semantics.symbols', function() {
* @return {boolean}
*/
isConstructor: function() {
- return this.name == PredefinedName.NEW;
+ return this.name == PredefinedName.CONSTRUCTOR;
}
});
View
4 traceur/src/syntax/ParseTreeValidator.js
@@ -466,9 +466,9 @@ traceur.define('syntax', function() {
},
/**
- * @param {traceur.syntax.trees.ForEachStatement} tree
+ * @param {traceur.syntax.trees.ForOfStatement} tree
*/
- visitForEachStatement: function(tree) {
+ visitForOfStatement: function(tree) {
this.checkVisit_(tree.initializer.declarations.length <= 1,
tree.initializer,
'for-each statement may not have more than one variable declaration');
View
4 traceur/src/syntax/ParseTreeVisitor.js
@@ -288,9 +288,9 @@ traceur.define('syntax', function() {
},
/**
- * @param {traceur.syntax.trees.ForEachStatement} tree
+ * @param {traceur.syntax.trees.ForOfStatement} tree
*/
- visitForEachStatement: function(tree) {
+ visitForOfStatement: function(tree) {
this.visitAny(tree.initializer);
this.visitAny(tree.collection);
this.visitAny(tree.body);
View
50 traceur/src/syntax/Parser.js
@@ -55,7 +55,7 @@ traceur.define('syntax', function() {
var ExpressionStatement = traceur.syntax.trees.ExpressionStatement;
var FieldDeclaration = traceur.syntax.trees.FieldDeclaration;
var Finally = traceur.syntax.trees.Finally;
- var ForEachStatement = traceur.syntax.trees.ForEachStatement;
+ var ForOfStatement = traceur.syntax.trees.ForOfStatement;
var ForInStatement = traceur.syntax.trees.ForInStatement;
var ForStatement = traceur.syntax.trees.ForStatement;
var FormalParameterList = traceur.syntax.trees.FormalParameterList;
@@ -844,8 +844,8 @@ traceur.define('syntax', function() {
this.eat_(TokenType.CLASS);
var name = this.eatId_();
var superClass = null;
- if (this.peek_(TokenType.COLON)) {
- this.eat_(TokenType.COLON);
+ if (this.peek_(TokenType.EXTENDS)) {
+ this.eat_(TokenType.EXTENDS);
superClass = this.parseExpression_();
}
this.eat_(TokenType.OPEN_CURLY);
@@ -878,8 +878,8 @@ traceur.define('syntax', function() {
case TokenType.IDENTIFIER:
case TokenType.VAR:
case TokenType.CONST:
- case TokenType.CLASS:
- case TokenType.NEW:
+ case TokenType.STATIC:
+ case TokenType.CONSTRUCTOR:
return true;
default:
return false;
@@ -921,7 +921,7 @@ traceur.define('syntax', function() {
parseFieldDeclaration_: function() {
var start = this.getTreeStartLocation_();
- var isStatic = this.eatOpt_(TokenType.CLASS) != null;
+ var isStatic = this.eatOpt_(TokenType.STATIC) != null;
var binding = this.peekType_();
var isConst = false;
@@ -1004,7 +1004,7 @@ traceur.define('syntax', function() {
*/
parseMethodDeclaration_: function(allowStatic) {
var start = this.getTreeStartLocation_();
- var isStatic = allowStatic && this.eatOpt_(TokenType.CLASS) != null;
+ var isStatic = allowStatic && this.eatOpt_(TokenType.STATIC) != null;
if (this.peekFunction_()) {
this.nextToken_(); // function or #
}
@@ -1016,7 +1016,7 @@ traceur.define('syntax', function() {
* @private
*/
peekMethodDeclaration_: function() {
- var index = this.peek_(TokenType.CLASS) ? 1 : 0;
+ var index = this.peek_(TokenType.STATIC) ? 1 : 0;
return this.peekFunction_(index) ||
(this.peek_(TokenType.IDENTIFIER, index) && this.peek_(TokenType.OPEN_PAREN, index + 1));
},
@@ -1027,7 +1027,7 @@ traceur.define('syntax', function() {
*/
parseConstructorDeclaration_: function() {
var start = this.getTreeStartLocation_();
- var isStatic = this.eatOpt_(TokenType.CLASS) != null;
+ var isStatic = this.eatOpt_(TokenType.STATIC) != null;
return this.parseFunctionDeclarationTail_(start, isStatic, this.eatIdName_());
},
@@ -1036,8 +1036,8 @@ traceur.define('syntax', function() {
* @private
*/
peekConstructorDeclaration_: function() {
- var index = this.peek_(TokenType.CLASS) ? 1 : 0;
- return this.peek_(TokenType.NEW, index) &&
+ var index = this.peek_(TokenType.STATIC) ? 1 : 0;
+ return this.peek_(TokenType.CONSTRUCTOR, index) &&
this.peek_(TokenType.OPEN_PAREN, index + 1);
},
@@ -1568,18 +1568,18 @@ traceur.define('syntax', function() {
}
return this.parseForInStatement_(start, variables);
- } else if (this.peek_(TokenType.COLON)) {
- // for-in: only one declaration allowed
+ } else if (this.peekPredefinedString_(PredefinedName.OF)) {
+ // for-of: only one declaration allowed
if (variables.declarations.length > 1) {
- this.reportError_('for-each statement may not have more than one variable declaration');
+ this.reportError_('for-of statement may not have more than one variable declaration');
}
- // for-each: initializer is illegal
+ // for-of: initializer is illegal
var declaration = variables.declarations[0];
if (declaration.initializer != null) {
- this.reportError_('for-each statement may not have initializer');
+ this.reportError_('for-of statement may not have initializer');
}
- return this.parseForEachStatement_(start, variables);
+ return this.parseForOfStatement_(start, variables);
} else {
// for statement: let and const must have initializers
this.checkInitializers_(variables);
@@ -1600,19 +1600,19 @@ traceur.define('syntax', function() {
},
// The for-each Statement
- // for ( { let | var } identifier : expression ) statement
+ // for ( { let | var } identifier of expression ) statement
/**
* @param {SourcePosition} start
* @param {VariableDeclarationList} initializer
* @return {ParseTree}
* @private
*/
- parseForEachStatement_: function(start, initializer) {
- this.eat_(TokenType.COLON);
+ parseForOfStatement_: function(start, initializer) {
+ this.eatId_(); // of
var collection = this.parseExpression_();
this.eat_(TokenType.CLOSE_PAREN);
var body = this.parseStatement_();
- return new ForEachStatement(this.getTreeLocation_(start), initializer, collection, body);
+ return new ForOfStatement(this.getTreeLocation_(start), initializer, collection, body);
},
/**
@@ -2162,7 +2162,7 @@ traceur.define('syntax', function() {
* @private
*/
peekGetAccessor_: function(allowStatic) {
- var index = allowStatic && this.peek_(TokenType.CLASS) ? 1 : 0;
+ var index = allowStatic && this.peek_(TokenType.STATIC) ? 1 : 0;
return this.peekPredefinedString_(PredefinedName.GET, index) && this.peekPropertyName_(index + 1);
},
@@ -2181,7 +2181,7 @@ traceur.define('syntax', function() {
*/
parseGetAccessor_: function() {
var start = this.getTreeStartLocation_();
- var isStatic = this.eatOpt_(TokenType.CLASS) != null;
+ var isStatic = this.eatOpt_(TokenType.STATIC) != null;
this.eatId_(); // get
var propertyName = this.nextToken_();
this.eat_(TokenType.OPEN_PAREN);
@@ -2196,7 +2196,7 @@ traceur.define('syntax', function() {
* @private
*/
peekSetAccessor_: function(allowStatic) {
- var index = allowStatic && this.peek_(TokenType.CLASS) ? 1 : 0;
+ var index = allowStatic && this.peek_(TokenType.STATIC) ? 1 : 0;
return this.peekPredefinedString_(PredefinedName.SET, index) && this.peekPropertyName_(index + 1);
},
@@ -2206,7 +2206,7 @@ traceur.define('syntax', function() {
*/
parseSetAccessor_: function() {
var start = this.getTreeStartLocation_();
- var isStatic = this.eatOpt_(TokenType.CLASS) != null;
+ var isStatic = this.eatOpt_(TokenType.STATIC) != null;
this.eatId_(); // set
var propertyName = this.nextToken_();
this.eat_(TokenType.OPEN_PAREN);
View
1  traceur/src/syntax/PredefinedName.js
@@ -59,6 +59,7 @@ traceur.define('syntax', function() {
NEW_STATE: '$newState',
OBJECT: 'Object',
OBJECT_NAME: 'Object',
+ OF: 'of',
PARAM: '$param',
PROTO: '__proto__',
PROTOTYPE: 'prototype',
View
2  traceur/src/syntax/trees/ParseTree.js
@@ -241,7 +241,7 @@ traceur.define('syntax.trees', function() {
case ParseTreeType.IF_STATEMENT:
case ParseTreeType.DO_WHILE_STATEMENT:
case ParseTreeType.WHILE_STATEMENT:
- case ParseTreeType.FOR_EACH_STATEMENT:
+ case ParseTreeType.FOR_OF_STATEMENT:
case ParseTreeType.FOR_IN_STATEMENT:
case ParseTreeType.FOR_STATEMENT:
case ParseTreeType.CONTINUE_STATEMENT:
View
2  traceur/src/syntax/trees/ParseTrees.js
@@ -324,7 +324,7 @@ traceur.define('syntax.trees', function() {
* @constructor
* @extends {ParseTree}
*/
- ForEachStatement: create('initializer', 'collection', 'body'),
+ ForOfStatement: create('initializer', 'collection', 'body'),
/**
* @param {traceur.util.SourceRange} location
View
2  traceur/src/traceur.js
@@ -178,7 +178,7 @@ var traceur = (function() {
'codegeneration/RestParameterTransformer.js',
'codegeneration/SpreadTransformer.js',
'codegeneration/UniqueIdentifierGenerator.js',
- 'codegeneration/ForEachTransformer.js',
+ 'codegeneration/ForOfTransformer.js',
'codegeneration/ModuleTransformer.js',
'codegeneration/FunctionTransformer.js',
'codegeneration/ClassTransformer.js',
Please sign in to comment.
Something went wrong with that request. Please try again.