--es6 option. closes #64

This commit is contained in:
Olov Lassus
2014-10-09 12:11:16 +02:00
parent 7700506b66
commit 5465a64410
3 changed files with 20 additions and 10 deletions
+3
View File
@@ -53,6 +53,8 @@ Use the `-o` option to write output to file.
Provide `-` instead of an input `<file>` to read input from stdin.
*experimental* Use the `--es6` option for ES6 support via the Acorn parser.
Use the `--sourcemap` option to generate an inline sourcemap.
Use the `--sourceroot` option to set the sourceRoot property of the generated sourcemap.
@@ -308,6 +310,7 @@ var ngAnnotate = require("ng-annotate");
var somePlugin = require("./some/path/some-plugin");
var res = ngAnnotate(src, {
add: true,
es6: true,
plugin: [somePlugin],
rename: [{from: "generalname", to: "uniquename"}, {from: "alpha", to: "beta"}],
sourcemap: true,
+12 -9
View File
@@ -3,12 +3,6 @@
// Copyright (c) 2013-2014 Olov Lassus <olov.lassus@gmail.com>
"use strict";
const useEsprima = true;
const parser_require_t0 = Date.now();
const acorn = (useEsprima ? null : require("acorn").parse);
const esprima = (useEsprima ? require("esprima").parse : null);
const parser_require_t1 = Date.now();
const fmt = require("simple-fmt");
const is = require("simple-is");
const alter = require("alter");
@@ -739,12 +733,21 @@ module.exports = function ngAnnotate(src, options) {
// [{type: "Block"|"Line", value: str, range: [from,to]}, ..]
let comments = [];
let esprima = null;
let acorn = null;
stats.parser_require_t0 = Date.now();
if (!options.es6) {
esprima = require("esprima").parse;
} else {
acorn = require("acorn").parse;
}
stats.parser_require_t1 = Date.now();
try {
stats.parser_require_t0 = parser_require_t0;
stats.parser_require_t1 = parser_require_t1;
stats.parser_parse_t0 = Date.now();
if (useEsprima) {
if (!options.es6) {
ast = esprima(src, {
range: true,
comment: true,
+5 -1
View File
@@ -29,6 +29,10 @@ const optimist = require("optimist")
.options("o", {
describe: "write output to <file>. output is written to stdout by default",
})
.options("es6", {
boolean: true,
describe: "support ES6 via the Acorn parser (experimental)",
})
.options("sourcemap", {
boolean: true,
describe: "generate an inline sourcemap"
@@ -123,7 +127,7 @@ function runAnnotate(err, src) {
config.inFile = filename;
}
["add", "remove", "o", "sourcemap", "sourceroot", "regexp", "rename", "single_quotes", "plugin", "stats"].forEach(function(opt) {
["add", "remove", "o", "sourcemap", "sourceroot", "regexp", "rename", "single_quotes", "plugin", "stats", "es6"].forEach(function(opt) {
if (opt in argv) {
config[opt] = argv[opt];
}