traceur-rails 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +20 -0
- data/Rakefile +12 -0
- data/lib/traceur-rails.rb +5 -0
- data/lib/traceur/config.rb +38 -0
- data/lib/traceur/sprockets.rb +4 -0
- data/lib/traceur/support/runner.js +21 -0
- data/lib/traceur/support/traceur/README.md +40 -0
- data/lib/traceur/support/traceur/bin/traceur-runtime.js +2039 -0
- data/lib/traceur/support/traceur/bin/traceur.js +23037 -0
- data/lib/traceur/support/traceur/package.json +60 -0
- data/lib/traceur/support/traceur/src/node/System.js +38 -0
- data/lib/traceur/support/traceur/src/node/api.js +124 -0
- data/lib/traceur/support/traceur/src/node/command.js +213 -0
- data/lib/traceur/support/traceur/src/node/compile-single-file.js +69 -0
- data/lib/traceur/support/traceur/src/node/compiler.js +113 -0
- data/lib/traceur/support/traceur/src/node/deferred.js +110 -0
- data/lib/traceur/support/traceur/src/node/file-util.js +73 -0
- data/lib/traceur/support/traceur/src/node/getopt.js +147 -0
- data/lib/traceur/support/traceur/src/node/inline-module.js +150 -0
- data/lib/traceur/support/traceur/src/node/interpreter.js +33 -0
- data/lib/traceur/support/traceur/src/node/nodeLoader.js +41 -0
- data/lib/traceur/support/traceur/src/node/require.js +85 -0
- data/lib/traceur/support/traceur/src/node/to-amd-compiler.js +33 -0
- data/lib/traceur/support/traceur/src/node/to-commonjs-compiler.js +33 -0
- data/lib/traceur/support/traceur/src/node/traceur.js +32 -0
- data/lib/traceur/support/traceur/traceur +3 -0
- data/lib/traceur/template.rb +61 -0
- data/lib/traceur/tilt.rb +4 -0
- data/lib/traceur/version.rb +3 -0
- data/test/template_test.rb +45 -0
- data/test/test_helper.rb +13 -0
- data/traceur-rails.gemspec +26 -0
- metadata +151 -0
@@ -0,0 +1,60 @@
|
|
1
|
+
{
|
2
|
+
"name": "traceur",
|
3
|
+
"version": "0.0.43",
|
4
|
+
"description": "ES6 to ES5 compiler",
|
5
|
+
"keywords": [
|
6
|
+
"javascript",
|
7
|
+
"ecmascript",
|
8
|
+
"language",
|
9
|
+
"es5",
|
10
|
+
"es6",
|
11
|
+
"ES.next",
|
12
|
+
"harmony",
|
13
|
+
"compiler",
|
14
|
+
"transpiler"
|
15
|
+
],
|
16
|
+
"author": {
|
17
|
+
"name": "Traceur Authors"
|
18
|
+
},
|
19
|
+
"license": "Apache License 2.0",
|
20
|
+
"engines": {
|
21
|
+
"node": ">=0.10"
|
22
|
+
},
|
23
|
+
"main": "./src/node/api.js",
|
24
|
+
"bin": {
|
25
|
+
"traceur": "./traceur"
|
26
|
+
},
|
27
|
+
"scripts": {
|
28
|
+
"test": "make test",
|
29
|
+
"start": "node ./demo/expressServer.js"
|
30
|
+
},
|
31
|
+
"homepage": "https://github.com/google/traceur-compiler",
|
32
|
+
"bugs": {
|
33
|
+
"url": "https://github.com/google/traceur-compiler/issues"
|
34
|
+
},
|
35
|
+
"repository": {
|
36
|
+
"type": "git",
|
37
|
+
"url": "https://github.com/google/traceur-compiler"
|
38
|
+
},
|
39
|
+
"dependencies": {
|
40
|
+
"commander": ">=1.1",
|
41
|
+
"q-io": "~1.10.6",
|
42
|
+
"semver": "*"
|
43
|
+
},
|
44
|
+
"devDependencies": {
|
45
|
+
"source-map": "0.1.30",
|
46
|
+
"mocha": ">=1.9",
|
47
|
+
"chai": ">=1.5",
|
48
|
+
"node-uuid": ">=1.4",
|
49
|
+
"rsvp": "3.0.3",
|
50
|
+
"requirejs": "~2.1.9",
|
51
|
+
"semver": "2.2.1",
|
52
|
+
"traceur": "0.0.42",
|
53
|
+
"promises-aplus-tests": "~2.0.4"
|
54
|
+
},
|
55
|
+
"subdomain": "traceur",
|
56
|
+
"readme": "[![Build Status](https://travis-ci.org/google/traceur-compiler.png)](https://travis-ci.org/google/traceur-compiler)\n\n<img src=\"https://raw.github.com/google/traceur-compiler/master/logo/tc.png\" alt=\"Traceur logo\" width=\"200px\">\n## What is Traceur?\n\nTraceur is a JavaScript.next-to-JavaScript-of-today compiler that allows you to\nuse features from the future **today**. Traceur's goal is to inform the design\nof new JavaScript features which are only valuable if they allow you to write\nbetter code. Traceur allows you to try out new and proposed\n[language features](https://github.com/google/traceur-compiler/wiki/LanguageFeatures)\ntoday, helping you say what you mean in your code while informing the standards process.\n\nJavaScript's evolution needs your input.\n[Try](https://github.com/google/traceur-compiler/wiki/GettingStarted) out the\nnew language features.\n[Tell us](http://groups.google.com/group/traceur-compiler-discuss)\nhow they work for you and what's still causing you to use more boilerplate and\n\"design patterns\" than you prefer.\n\n## What now? What can Traceur do for me?\n\nRead the\n[Getting Started](https://github.com/google/traceur-compiler/wiki/GettingStarted)\npage to get up and running. You can use some language features right now and\neven try it out in your browser\n[here](http://google.github.io/traceur-compiler/demo/repl.html).\nJust type in some code and see what Traceur produces. For an idea of what is\navailable and what we have in the pipeline, see the\n[Language Features](https://github.com/google/traceur-compiler/wiki/LanguageFeatures)\npage.\n\nThe JSConf 2011 presentation of Traceur describes the goals of the project and\nwhat it can do today. Some documentation is on the wiki on this site.\nExtra demos are in the source repository.\n\nWe also presented Traceur at NodeConf 2011. The video is\navailable on [YouTube](http://www.youtube.com/watch?feature=player_detailpage&v=ntDZa7ekFEA).\n\nQuestions, suggestions, and comments can be directed to the\n[discussion group](http://groups.google.com/group/traceur-compiler-discuss).\n",
|
57
|
+
"readmeFilename": "README.md",
|
58
|
+
"_id": "traceur@0.0.43",
|
59
|
+
"_from": "traceur@"
|
60
|
+
}
|
@@ -0,0 +1,38 @@
|
|
1
|
+
// Copyright 2014 Traceur Authors.
|
2
|
+
//
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
// you may not use this file except in compliance with the License.
|
5
|
+
// You may obtain a copy of the License at
|
6
|
+
//
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
//
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
// See the License for the specific language governing permissions and
|
13
|
+
// limitations under the License.
|
14
|
+
|
15
|
+
'use strict';
|
16
|
+
|
17
|
+
var fs = require('fs');
|
18
|
+
var traceur = require('./traceur.js');
|
19
|
+
var nodeLoader = require('./nodeLoader.js');
|
20
|
+
var path = require('path');
|
21
|
+
var reporter = new traceur.util.ErrorReporter();
|
22
|
+
var LoaderHooks = traceur.runtime.LoaderHooks;
|
23
|
+
var url = (path.resolve('./') + '/').replace(/\\/g, '/');
|
24
|
+
var loaderHooks = new LoaderHooks(reporter, url, nodeLoader);
|
25
|
+
|
26
|
+
var System = new traceur.runtime.TraceurLoader(loaderHooks);
|
27
|
+
|
28
|
+
global.System = System;
|
29
|
+
|
30
|
+
// If we are compiling into a package namespace, set up an alias table
|
31
|
+
// for the versions of the package.
|
32
|
+
var referrerName = traceur.options.referrer;
|
33
|
+
if (referrerName)
|
34
|
+
System.map = System.semverMap(referrerName);
|
35
|
+
else
|
36
|
+
System.map = System.semverMap(System.version);
|
37
|
+
|
38
|
+
module.exports = System;
|
@@ -0,0 +1,124 @@
|
|
1
|
+
// Copyright 2013 Traceur Authors.
|
2
|
+
//
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
// you may not use this file except in compliance with the License.
|
5
|
+
// You may obtain a copy of the License at
|
6
|
+
//
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
//
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
// See the License for the specific language governing permissions and
|
13
|
+
// limitations under the License.
|
14
|
+
|
15
|
+
// Node.js API
|
16
|
+
//
|
17
|
+
// This is what you get when you `require('traceur')`.
|
18
|
+
// It's suppose to be used by custom scripts or tools such as Grunt or Karma.
|
19
|
+
|
20
|
+
'use strict';
|
21
|
+
|
22
|
+
var path = require('path');
|
23
|
+
var traceur = require('./traceur.js');
|
24
|
+
var AttachModuleNameTransformer =
|
25
|
+
traceur.codegeneration.module.AttachModuleNameTransformer;
|
26
|
+
var ErrorReporter = traceur.util.TestErrorReporter;
|
27
|
+
var FromOptionsTransformer = traceur.codegeneration.FromOptionsTransformer;
|
28
|
+
var PureES6Transformer = traceur.codegeneration.PureES6Transformer;
|
29
|
+
var Parser = traceur.syntax.Parser;
|
30
|
+
var SourceFile = traceur.syntax.SourceFile;
|
31
|
+
var SourceMapGenerator = traceur.outputgeneration.SourceMapGenerator;
|
32
|
+
var TreeWriter = traceur.outputgeneration.TreeWriter;
|
33
|
+
var traceurOptions = traceur.options;
|
34
|
+
|
35
|
+
function merge(dest) {
|
36
|
+
var src, i;
|
37
|
+
for (i = 1; i < arguments.length; i++) {
|
38
|
+
src = arguments[i];
|
39
|
+
Object.keys(src).forEach(function(key) {
|
40
|
+
dest[key] = src[key];
|
41
|
+
});
|
42
|
+
}
|
43
|
+
|
44
|
+
return dest;
|
45
|
+
}
|
46
|
+
|
47
|
+
// The absolute path to traceur-runtime.js -- the file that should be executed
|
48
|
+
// if you want to run Traceur-compiled scripts when the compiler isn't present.
|
49
|
+
var RUNTIME_PATH = path.join(__dirname, '../../bin/traceur-runtime.js');
|
50
|
+
|
51
|
+
/**
|
52
|
+
* Compile ES6 source code with Traceur.
|
53
|
+
*
|
54
|
+
* TODO(vojta): Support source maps.
|
55
|
+
*
|
56
|
+
* @param {string} content ES6 source code.
|
57
|
+
* @param {Object=} options Traceur options.
|
58
|
+
* @return {string} Transpiled ES5 code.
|
59
|
+
*/
|
60
|
+
function compile(content, options) {
|
61
|
+
options = merge({
|
62
|
+
outputLanguage: 'es5',
|
63
|
+
modules: 'commonjs',
|
64
|
+
filename: '<unknown file>',
|
65
|
+
sourceMap: false,
|
66
|
+
cwd: process.cwd(),
|
67
|
+
moduleName: false
|
68
|
+
}, options || {});
|
69
|
+
|
70
|
+
var moduleName = options.moduleName;
|
71
|
+
|
72
|
+
traceurOptions.reset();
|
73
|
+
merge(traceurOptions, options);
|
74
|
+
|
75
|
+
var errorReporter = new ErrorReporter();
|
76
|
+
var sourceFile = new SourceFile(options.filename, content);
|
77
|
+
var parser = new Parser(sourceFile, errorReporter);
|
78
|
+
var tree = parser.parseModule();
|
79
|
+
var transformer;
|
80
|
+
if (moduleName === true || options.modules == 'register' || options.modules == 'inline') {
|
81
|
+
moduleName = options.filename.replace(/\.js$/, '');
|
82
|
+
moduleName = path.relative(options.cwd, moduleName).replace(/\\/g,'/');
|
83
|
+
}
|
84
|
+
if (moduleName) {
|
85
|
+
transformer = new AttachModuleNameTransformer(moduleName);
|
86
|
+
tree = transformer.transformAny(tree);
|
87
|
+
}
|
88
|
+
|
89
|
+
if (options.outputLanguage.toLowerCase() === 'es6') {
|
90
|
+
transformer = new PureES6Transformer(errorReporter);
|
91
|
+
} else {
|
92
|
+
transformer = new FromOptionsTransformer(errorReporter);
|
93
|
+
}
|
94
|
+
|
95
|
+
var transformedTree = transformer.transform(tree);
|
96
|
+
|
97
|
+
if (errorReporter.hadError()) {
|
98
|
+
return {
|
99
|
+
js: null,
|
100
|
+
errors: errorReporter.errors,
|
101
|
+
sourceMap: null
|
102
|
+
};
|
103
|
+
}
|
104
|
+
|
105
|
+
var treeWriterOptions = {};
|
106
|
+
|
107
|
+
if (options.sourceMap) {
|
108
|
+
treeWriterOptions.sourceMapGenerator = new SourceMapGenerator({
|
109
|
+
file: options.filename,
|
110
|
+
sourceRoot: null
|
111
|
+
});
|
112
|
+
}
|
113
|
+
|
114
|
+
return {
|
115
|
+
js: TreeWriter.write(transformedTree, treeWriterOptions),
|
116
|
+
errors: errorReporter.errors,
|
117
|
+
sourceMap: treeWriterOptions.sourceMap || null
|
118
|
+
};
|
119
|
+
};
|
120
|
+
|
121
|
+
// extend traceur module
|
122
|
+
module.exports = Object.create(traceur);
|
123
|
+
module.exports.compile = compile;
|
124
|
+
module.exports.RUNTIME_PATH = RUNTIME_PATH;
|
@@ -0,0 +1,213 @@
|
|
1
|
+
// Copyright 2013 Traceur Authors.
|
2
|
+
//
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
// you may not use this file except in compliance with the License.
|
5
|
+
// You may obtain a copy of the License at
|
6
|
+
//
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
//
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
// See the License for the specific language governing permissions and
|
13
|
+
// limitations under the License.
|
14
|
+
|
15
|
+
'use strict';
|
16
|
+
|
17
|
+
var path = require('path');
|
18
|
+
var flags;
|
19
|
+
var cmdName = path.basename(process.argv[1]);
|
20
|
+
try {
|
21
|
+
flags = new (require('commander').Command)(cmdName);
|
22
|
+
} catch (ex) {
|
23
|
+
console.error('Commander.js is required for this to work. To install it ' +
|
24
|
+
'run:\n\n npm install commander\n');
|
25
|
+
process.exit(1);
|
26
|
+
}
|
27
|
+
flags.setMaxListeners(100);
|
28
|
+
|
29
|
+
var traceur = require('./traceur.js');
|
30
|
+
|
31
|
+
// The System object requires traceur, but we want it set for everything that
|
32
|
+
// follows. The module sets global.System as a side-effect.
|
33
|
+
require('./System.js');
|
34
|
+
|
35
|
+
flags.option('--out <FILE>', 'Compile all input files into a single file');
|
36
|
+
flags.option('--referrer <name>',
|
37
|
+
'Prefix compiled code with System.referrName');
|
38
|
+
|
39
|
+
flags.option('--dir <INDIR> <OUTDIR>', 'Compile an input directory of modules into an output directory');
|
40
|
+
|
41
|
+
flags.option('--sourcemap', 'Generate source maps');
|
42
|
+
flags.on('sourcemap', function() {
|
43
|
+
flags.sourceMaps = traceur.options.sourceMaps = true;
|
44
|
+
});
|
45
|
+
|
46
|
+
flags.option('--longhelp', 'Show all known options');
|
47
|
+
flags.on('longhelp', function() {
|
48
|
+
flags.help();
|
49
|
+
process.exit();
|
50
|
+
});
|
51
|
+
|
52
|
+
// Caling process.exit when there is still characters to be flushed to stdout
|
53
|
+
// makes Windows drop those characters. We therefor wait until the buffer is
|
54
|
+
// empty before really exiting.
|
55
|
+
// Since this makes exiting async we need to manually keep track
|
56
|
+
var shouldExit = false;
|
57
|
+
|
58
|
+
function processExit() {
|
59
|
+
shouldExit = true;
|
60
|
+
var draining = 0;
|
61
|
+
function exit() {
|
62
|
+
if (!draining--)
|
63
|
+
process.exit();
|
64
|
+
}
|
65
|
+
if (process.stdout.bufferSize) {
|
66
|
+
draining += 1;
|
67
|
+
process.stdout.once('drain', exit);
|
68
|
+
}
|
69
|
+
if (process.stderr.bufferSize) {
|
70
|
+
draining += 1;
|
71
|
+
process.stderr.once('drain', exit);
|
72
|
+
}
|
73
|
+
exit();
|
74
|
+
}
|
75
|
+
|
76
|
+
flags.option('-v, --version', 'Show version and exit');
|
77
|
+
flags.on('version', function() {
|
78
|
+
process.stdout.write(System.version.split('@')[1]);
|
79
|
+
processExit();
|
80
|
+
});
|
81
|
+
|
82
|
+
flags.on('--help', function() {
|
83
|
+
console.log(' Examples:');
|
84
|
+
console.log('');
|
85
|
+
console.log(' $ %s a.js [args]', cmdName);
|
86
|
+
console.log(' $ %s --out compiled.js b.js c.js', cmdName);
|
87
|
+
console.log(' $ %s --dir indir outdir', cmdName);
|
88
|
+
console.log('');
|
89
|
+
});
|
90
|
+
|
91
|
+
traceur.options.addOptions(flags);
|
92
|
+
|
93
|
+
flags.usage('[options] [files]');
|
94
|
+
|
95
|
+
// Override commander.js's optionHelp to filter out the Traceur feature flags
|
96
|
+
// from showing up in the help message.
|
97
|
+
var optionHelp = flags.optionHelp;
|
98
|
+
flags.optionHelp = function() {
|
99
|
+
if (!flags.longhelp) {
|
100
|
+
this.options = this.options.filter(function(command) {
|
101
|
+
var dashedName = command.long.slice(2);
|
102
|
+
return traceur.options.filterOption(dashedName);
|
103
|
+
});
|
104
|
+
}
|
105
|
+
return optionHelp.call(this);
|
106
|
+
}
|
107
|
+
|
108
|
+
/**
|
109
|
+
* HACK: Process arguments so that in interpret mode, commander.js only parses
|
110
|
+
* the flags, without the file name and anything past that. If an invalid flag
|
111
|
+
* is encountered, commander.js error reporting is emulated instead.
|
112
|
+
* @param {Array.<string>} argv
|
113
|
+
* @return {Array.<string>}
|
114
|
+
*/
|
115
|
+
function processArguments(argv) {
|
116
|
+
// Preserve the original.
|
117
|
+
argv = argv.slice();
|
118
|
+
|
119
|
+
var interpretMode = true;
|
120
|
+
for (var i = 2; i < argv.length; i++) {
|
121
|
+
var arg = argv[i], index;
|
122
|
+
if (arg === '--')
|
123
|
+
break;
|
124
|
+
|
125
|
+
// Normalize flags in-place.
|
126
|
+
if (arg.length > 2 && arg[0] === '-' && arg[1] !== '-') {
|
127
|
+
// TODO: Is this needed at all for traceur?
|
128
|
+
arg = arg.slice(1).split('').map(function(flag) {
|
129
|
+
return '-' + flag;
|
130
|
+
});
|
131
|
+
// Insert the normalized flags in argv.
|
132
|
+
argv.splice.apply(argv, [i, 1].concat(arg));
|
133
|
+
// Grab the first normalized flag and process it as usual.
|
134
|
+
arg = argv[i];
|
135
|
+
} else if (/^--/.test(arg) && (index = arg.indexOf('=')) !== -1) {
|
136
|
+
// Insert the flag argument in argv.
|
137
|
+
argv.splice(i + 1, 0, arg.slice(index + 1));
|
138
|
+
// Replace the flag with the stripped version and process it as usual.
|
139
|
+
arg = argv[i] = arg.slice(0, index);
|
140
|
+
}
|
141
|
+
|
142
|
+
var option = flags.optionFor(arg);
|
143
|
+
if (option) {
|
144
|
+
if (arg === '--out' || arg === '--dir')
|
145
|
+
interpretMode = false;
|
146
|
+
|
147
|
+
if (option.required)
|
148
|
+
i++;
|
149
|
+
else if (option.optional) {
|
150
|
+
arg = argv[i + 1];
|
151
|
+
if (arg && arg[0] !== '-')
|
152
|
+
i++;
|
153
|
+
}
|
154
|
+
} else if (arg === '-h' || arg === '--help') {
|
155
|
+
// HACK: Special case for the implicit help flags, which can't have
|
156
|
+
// their own option, as --help would set flags.help to true, shadowing
|
157
|
+
// the flags.help() method.
|
158
|
+
} else if (arg[0] === '-') {
|
159
|
+
// HACK: Because commander.js has a flexible policy, this is the only
|
160
|
+
// reliable way of reporting invalid flags to the user, and it's limited
|
161
|
+
// to the first invalid flag encountered.
|
162
|
+
console.log('\n error: unknown option `%s\'\n', arg);
|
163
|
+
process.exit(1);
|
164
|
+
} else if (interpretMode) {
|
165
|
+
// Add a hint to stop commander.js from parsing following arguments.
|
166
|
+
// Note that this means that --out must come before any unknown flag as
|
167
|
+
// well as before any filename for it to be used as the out flag.
|
168
|
+
argv.splice(i, 0, '--');
|
169
|
+
// Save traceur flags for interpret.js.
|
170
|
+
argv.flags = argv.slice(2, i);
|
171
|
+
break;
|
172
|
+
}
|
173
|
+
}
|
174
|
+
return argv;
|
175
|
+
}
|
176
|
+
|
177
|
+
var argv = processArguments(process.argv);
|
178
|
+
flags.parse(argv);
|
179
|
+
|
180
|
+
|
181
|
+
var includes = traceur.options.scripts || [];
|
182
|
+
includes = includes.concat(flags.args);
|
183
|
+
|
184
|
+
if (!shouldExit && !includes.length) {
|
185
|
+
// TODO: Start trepl
|
186
|
+
console.error('\n Error: At least one input file is needed');
|
187
|
+
flags.help();
|
188
|
+
process.exit(1);
|
189
|
+
}
|
190
|
+
|
191
|
+
|
192
|
+
var interpret = require('./interpreter.js');
|
193
|
+
var compiler = require('./compiler.js');
|
194
|
+
var compileToSingleFile = compiler.compileToSingleFile;
|
195
|
+
var compileToDirectory = compiler.compileToDirectory;
|
196
|
+
|
197
|
+
var out = flags.out;
|
198
|
+
var dir = flags.dir;
|
199
|
+
if (!shouldExit) {
|
200
|
+
if (out) {
|
201
|
+
var isSingleFileCompile = /\.js$/.test(out);
|
202
|
+
if (isSingleFileCompile)
|
203
|
+
compileToSingleFile(out, includes, flags.sourceMaps);
|
204
|
+
else
|
205
|
+
compileToDirectory(out, includes, flags.sourceMaps);
|
206
|
+
} else if (dir) {
|
207
|
+
var compileAllJsFilesInDir = require('./compile-single-file.js').compileAllJsFilesInDir;
|
208
|
+
compileAllJsFilesInDir(dir, includes[0], true);
|
209
|
+
}
|
210
|
+
else {
|
211
|
+
interpret(path.resolve(includes[0]), includes.slice(1), argv.flags);
|
212
|
+
}
|
213
|
+
}
|
@@ -0,0 +1,69 @@
|
|
1
|
+
// Copyright 2013 Traceur Authors.
|
2
|
+
//
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
// you may not use this file except in compliance with the License.
|
5
|
+
// You may obtain a copy of the License at
|
6
|
+
//
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
//
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
// See the License for the specific language governing permissions and
|
13
|
+
// limitations under the License.
|
14
|
+
|
15
|
+
'use strict';
|
16
|
+
|
17
|
+
var fs = require('q-io/fs');
|
18
|
+
var path = require('path');
|
19
|
+
var writeTreeToFile = require('./compiler.js').writeTreeToFile;
|
20
|
+
|
21
|
+
var traceur = require('./traceur.js');
|
22
|
+
var ErrorReporter = traceur.util.ErrorReporter;
|
23
|
+
var AttachModuleNameTransformer =
|
24
|
+
traceur.codegeneration.module.AttachModuleNameTransformer;
|
25
|
+
var FromOptionsTransformer = traceur.codegeneration.FromOptionsTransformer;
|
26
|
+
var Parser = traceur.syntax.Parser;
|
27
|
+
var SourceFile = traceur.syntax.SourceFile;
|
28
|
+
|
29
|
+
function compileSingleFile(inputFilePath, outputFilePath, anonymousModules) {
|
30
|
+
return fs.read(inputFilePath).then(function(contents) {
|
31
|
+
var reporter = new ErrorReporter();
|
32
|
+
var sourceFile = new SourceFile(inputFilePath, contents);
|
33
|
+
var parser = new Parser(sourceFile, reporter);
|
34
|
+
var tree = parser.parseModule();
|
35
|
+
var moduleName, transformer;
|
36
|
+
if (!anonymousModules) {
|
37
|
+
moduleName = inputFilePath.replace(/\.js$/, '').replace(/\\/g,'/');
|
38
|
+
// Module naming uses ./ to signal relative names.
|
39
|
+
if (moduleName[0] !== '/')
|
40
|
+
moduleName = './' + moduleName;
|
41
|
+
transformer = new AttachModuleNameTransformer(moduleName);
|
42
|
+
tree = transformer.transformAny(tree);
|
43
|
+
}
|
44
|
+
transformer = new FromOptionsTransformer(reporter);
|
45
|
+
var transformed = transformer.transform(tree);
|
46
|
+
|
47
|
+
if (!reporter.hadError()) {
|
48
|
+
writeTreeToFile(transformed, outputFilePath);
|
49
|
+
}
|
50
|
+
});
|
51
|
+
}
|
52
|
+
|
53
|
+
function onlyJsFiles(path, stat) {
|
54
|
+
return stat.isFile() && /\.js$/.test(path) || false;
|
55
|
+
}
|
56
|
+
|
57
|
+
function compileAllJsFilesInDir(inputDir, outputDir, anonymousModules) {
|
58
|
+
inputDir = path.normalize(inputDir);
|
59
|
+
outputDir = path.normalize(outputDir);
|
60
|
+
fs.listTree(inputDir, onlyJsFiles).then(function(files) {
|
61
|
+
files.forEach(function(inputFilePath) {
|
62
|
+
var outputFilePath = inputFilePath.replace(inputDir, outputDir);
|
63
|
+
compileSingleFile(inputFilePath, outputFilePath, anonymousModules).done();
|
64
|
+
});
|
65
|
+
}).done();
|
66
|
+
}
|
67
|
+
|
68
|
+
compileSingleFile.compileAllJsFilesInDir = compileAllJsFilesInDir;
|
69
|
+
module.exports = compileSingleFile;
|