Compare commits
22 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
34f02f06a6 | ||
|
|
6d3fe5b85c | ||
|
|
3878bd812c | ||
|
|
0717eaddce | ||
|
|
102cbbe493 | ||
|
|
d981b30194 | ||
|
|
0fc02f2cf0 | ||
|
|
f24b5164d4 | ||
|
|
4be27ee72c | ||
|
|
f0070e4828 | ||
|
|
ce8beec22c | ||
|
|
b30bdf2294 | ||
|
|
63b44a3e6e | ||
|
|
95de5400e6 | ||
|
|
fe7079802b | ||
|
|
61ddb14e25 | ||
|
|
ca7a93cd64 | ||
|
|
90a1c81d30 | ||
|
|
5e9089d104 | ||
|
|
1a716943bc | ||
|
|
c28415c38a | ||
|
|
e1491de6b8 |
12
CHANGELOG.md
12
CHANGELOG.md
@@ -13,6 +13,18 @@ _Note: Gaps between patch versions are faulty/broken releases._
|
|||||||
|
|
||||||
See [CHANGELOG - 6to5](CHANGELOG-6to5.md) for the pre-4.0.0 version changelog.
|
See [CHANGELOG - 6to5](CHANGELOG-6to5.md) for the pre-4.0.0 version changelog.
|
||||||
|
|
||||||
|
## 5.2.7
|
||||||
|
|
||||||
|
* **Bug Fix**
|
||||||
|
* Move `utility.deadCodeElimination` transformer up to avoid race conditions.
|
||||||
|
* Fix shorthand property scope binding renaming.
|
||||||
|
* **Polish**
|
||||||
|
* Turn helper variable declarations into function declarations if possible.
|
||||||
|
* **Internal**
|
||||||
|
* Removed native inheritance support from classes.
|
||||||
|
* Added `replaceWithSourceString` path API.
|
||||||
|
* Split up `es3.propertyLiterals` and `es3.memberExpressionLiterals` transformers to `minfication.propertyLiterals` and `es3.memberExpressionLiterals`.
|
||||||
|
|
||||||
## 5.2.6
|
## 5.2.6
|
||||||
|
|
||||||
* **Internal**
|
* **Internal**
|
||||||
|
|||||||
1
Makefile
1
Makefile
@@ -3,7 +3,6 @@ BROWSERIFY_CMD = node_modules/browserify/bin/cmd.js
|
|||||||
ISTANBUL_CMD = node_modules/istanbul/lib/cli.js cover
|
ISTANBUL_CMD = node_modules/istanbul/lib/cli.js cover
|
||||||
UGLIFY_CMD = node_modules/uglify-js/bin/uglifyjs
|
UGLIFY_CMD = node_modules/uglify-js/bin/uglifyjs
|
||||||
#UGLIFY_CMD = node_modules/uglify-js/bin/uglifyjs --mangle sort
|
#UGLIFY_CMD = node_modules/uglify-js/bin/uglifyjs --mangle sort
|
||||||
JSHINT_CMD = node_modules/jshint/bin/jshint
|
|
||||||
MOCHA_CMD = node_modules/mocha/bin/_mocha
|
MOCHA_CMD = node_modules/mocha/bin/_mocha
|
||||||
BABEL_CMD = node_modules/babel/bin/babel
|
BABEL_CMD = node_modules/babel/bin/babel
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "babel-core",
|
"name": "babel-core",
|
||||||
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
|
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
|
||||||
"version": "5.2.6",
|
"version": "5.2.7",
|
||||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||||
"homepage": "https://babeljs.io/",
|
"homepage": "https://babeljs.io/",
|
||||||
"repository": "babel/babel",
|
"repository": "babel/babel",
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ module.exports = function (commander, filenames, opts) {
|
|||||||
var handleFile = function (src, filename) {
|
var handleFile = function (src, filename) {
|
||||||
if (util.shouldIgnore(src)) return;
|
if (util.shouldIgnore(src)) return;
|
||||||
|
|
||||||
if (util.canCompile(filename)) {
|
if (util.canCompile(filename, commander.extensions)) {
|
||||||
write(src, filename);
|
write(src, filename);
|
||||||
} else if (commander.copyFiles) {
|
} else if (commander.copyFiles) {
|
||||||
outputFileSync(path.join(commander.outDir, filename), fs.readFileSync(src));
|
outputFileSync(path.join(commander.outDir, filename), fs.readFileSync(src));
|
||||||
|
|||||||
@@ -1,14 +1,15 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
var commander = require("commander");
|
var moduleFormatters = require("babel-core/lib/babel/transformation/modules");
|
||||||
var transform = require("babel-core").transform;
|
var commander = require("commander");
|
||||||
var kebabCase = require("lodash/string/kebabCase");
|
var transform = require("babel-core").transform;
|
||||||
var options = require("babel-core").options;
|
var kebabCase = require("lodash/string/kebabCase");
|
||||||
var util = require("babel-core").util;
|
var options = require("babel-core").options;
|
||||||
var each = require("lodash/collection/each");
|
var util = require("babel-core").util;
|
||||||
var keys = require("lodash/object/keys");
|
var each = require("lodash/collection/each");
|
||||||
var fs = require("fs");
|
var keys = require("lodash/object/keys");
|
||||||
var glob = require("glob");
|
var fs = require("fs");
|
||||||
|
var glob = require("glob");
|
||||||
|
|
||||||
each(options, function (option, key) {
|
each(options, function (option, key) {
|
||||||
if (option.hidden) return;
|
if (option.hidden) return;
|
||||||
@@ -36,6 +37,7 @@ each(options, function (option, key) {
|
|||||||
commander.option(arg, desc.join(" "));
|
commander.option(arg, desc.join(" "));
|
||||||
})
|
})
|
||||||
|
|
||||||
|
commander.option("-x, --extensions [extensions]", "List of extensions to compile when a directory has been input [.es6,.js,.es,.jsx]");
|
||||||
commander.option("-w, --watch", "Recompile files on changes");
|
commander.option("-w, --watch", "Recompile files on changes");
|
||||||
commander.option("-o, --out-file [out]", "Compile all input files into a single file");
|
commander.option("-o, --out-file [out]", "Compile all input files into a single file");
|
||||||
commander.option("-d, --out-dir [out]", "Compile an input directory of modules into an output directory");
|
commander.option("-d, --out-dir [out]", "Compile an input directory of modules into an output directory");
|
||||||
@@ -57,8 +59,8 @@ commander.on("--help", function () {
|
|||||||
console.log();
|
console.log();
|
||||||
};
|
};
|
||||||
|
|
||||||
outKeys("Transformers", transform.transformers);
|
outKeys("Transformers", transform.pipeline.transformers);
|
||||||
outKeys("Module formatters", transform.moduleFormatters);
|
outKeys("Module formatters", moduleFormatters);
|
||||||
});
|
});
|
||||||
|
|
||||||
var pkg = require("../../package.json");
|
var pkg = require("../../package.json");
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
{
|
{
|
||||||
"name": "babel",
|
"name": "babel",
|
||||||
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
|
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
|
||||||
"version": "5.2.5",
|
"version": "5.2.6",
|
||||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||||
"homepage": "https://babeljs.io/",
|
"homepage": "https://babeljs.io/",
|
||||||
"repository": "babel/babel",
|
"repository": "babel/babel",
|
||||||
"preferGlobal": true,
|
"preferGlobal": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"babel-core": "^5.2.5",
|
"babel-core": "^5.2.6",
|
||||||
"chokidar": "^1.0.0",
|
"chokidar": "^1.0.0",
|
||||||
"commander": "^2.6.0",
|
"commander": "^2.6.0",
|
||||||
"convert-source-map": "^1.1.0",
|
"convert-source-map": "^1.1.0",
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "babel-runtime",
|
"name": "babel-runtime",
|
||||||
"description": "babel selfContained runtime",
|
"description": "babel selfContained runtime",
|
||||||
"version": "5.2.5",
|
"version": "5.2.6",
|
||||||
"repository": "babel/babel",
|
"repository": "babel/babel",
|
||||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ export { default as TransformerPipeline } from "../transformation/transformer-pi
|
|||||||
export { default as traverse } from "../traversal";
|
export { default as traverse } from "../traversal";
|
||||||
export { default as buildExternalHelpers } from "../tools/build-external-helpers";
|
export { default as buildExternalHelpers } from "../tools/build-external-helpers";
|
||||||
export { version } from "../../../package";
|
export { version } from "../../../package";
|
||||||
|
export { all as parse } from "../helpers/parse";
|
||||||
|
|
||||||
import * as t from "../types";
|
import * as t from "../types";
|
||||||
export { t as types };
|
export { t as types };
|
||||||
@@ -55,19 +56,3 @@ export function transformFileSync(filename: string, opts?: Object = {}) {
|
|||||||
opts.filename = filename;
|
opts.filename = filename;
|
||||||
return transform(fs.readFileSync(filename), opts);
|
return transform(fs.readFileSync(filename), opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function parse(code, opts = {}) {
|
|
||||||
opts.sourceType = "module";
|
|
||||||
opts.ecmaVersion = Infinity;
|
|
||||||
opts.plugins = {
|
|
||||||
flow: true,
|
|
||||||
jsx: true
|
|
||||||
};
|
|
||||||
opts.features = {};
|
|
||||||
|
|
||||||
for (var key in transform.pipeline.transformers) {
|
|
||||||
opts.features[key] = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return acorn.parse(code, opts);
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ var shouldIgnore = function (filename) {
|
|||||||
|
|
||||||
var istanbulMonkey = {};
|
var istanbulMonkey = {};
|
||||||
|
|
||||||
if (process.env.running_under_istanbul) { // jshint ignore:line
|
if (process.env.running_under_istanbul) {
|
||||||
// we need to monkey patch fs.readFileSync so we can hook into
|
// we need to monkey patch fs.readFileSync so we can hook into
|
||||||
// what istanbul gets, it's extremely dirty but it's the only way
|
// what istanbul gets, it's extremely dirty but it's the only way
|
||||||
var _readFileSync = fs.readFileSync;
|
var _readFileSync = fs.readFileSync;
|
||||||
@@ -117,7 +117,7 @@ var registerExtension = function (ext) {
|
|||||||
var old = oldHandlers[ext] || oldHandlers[".js"];
|
var old = oldHandlers[ext] || oldHandlers[".js"];
|
||||||
|
|
||||||
var loader = normalLoader;
|
var loader = normalLoader;
|
||||||
if (process.env.running_under_istanbul) loader = istanbulLoader; // jshint ignore:line
|
if (process.env.running_under_istanbul) loader = istanbulLoader;
|
||||||
|
|
||||||
require.extensions[ext] = function (m, filename) {
|
require.extensions[ext] = function (m, filename) {
|
||||||
if (shouldIgnore(filename)) {
|
if (shouldIgnore(filename)) {
|
||||||
|
|||||||
@@ -232,14 +232,14 @@ class CodeGenerator {
|
|||||||
this.map.mark(node, "end");
|
this.map.mark(node, "end");
|
||||||
if (opts.after) opts.after();
|
if (opts.after) opts.after();
|
||||||
|
|
||||||
|
this.format.concise = oldConcise;
|
||||||
|
|
||||||
newline(false);
|
newline(false);
|
||||||
|
|
||||||
this.printTrailingComments(node, parent);
|
this.printTrailingComments(node, parent);
|
||||||
} else {
|
} else {
|
||||||
throw new ReferenceError(`unknown node of type ${JSON.stringify(node.type)} with constructor ${JSON.stringify(node && node.constructor.name)}`);
|
throw new ReferenceError(`unknown node of type ${JSON.stringify(node.type)} with constructor ${JSON.stringify(node && node.constructor.name)}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.format.concise = oldConcise;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
printJoin(print, nodes, opts = {}) {
|
printJoin(print, nodes, opts = {}) {
|
||||||
|
|||||||
@@ -1,65 +1,51 @@
|
|||||||
import normalizeAst from "./normalize-ast";
|
import normalizeAst from "./normalize-ast";
|
||||||
import estraverse from "estraverse";
|
import estraverse from "estraverse";
|
||||||
import codeFrame from "./code-frame";
|
|
||||||
import * as acorn from "../../acorn";
|
import * as acorn from "../../acorn";
|
||||||
|
|
||||||
export default function (opts, code, callback) {
|
export default function (code, opts = {}) {
|
||||||
try {
|
var comments = [];
|
||||||
var comments = [];
|
var tokens = [];
|
||||||
var tokens = [];
|
|
||||||
|
|
||||||
var parseOpts = {
|
var parseOpts = {
|
||||||
allowImportExportEverywhere: opts.looseModules,
|
allowImportExportEverywhere: opts.looseModules,
|
||||||
allowReturnOutsideFunction: opts.looseModules,
|
allowReturnOutsideFunction: opts.looseModules,
|
||||||
ecmaVersion: 6,
|
allowHashBang: true,
|
||||||
strictMode: opts.strictMode,
|
ecmaVersion: 6,
|
||||||
sourceType: opts.sourceType,
|
strictMode: opts.strictMode,
|
||||||
onComment: comments,
|
sourceType: opts.sourceType,
|
||||||
locations: true,
|
locations: true,
|
||||||
features: opts.features || {},
|
onComment: comments,
|
||||||
plugins: opts.plugins || {},
|
features: opts.features || {},
|
||||||
onToken: tokens,
|
plugins: opts.plugins || {},
|
||||||
ranges: true
|
onToken: tokens,
|
||||||
};
|
ranges: true
|
||||||
|
};
|
||||||
|
|
||||||
if (opts.nonStandard) {
|
if (opts.nonStandard) {
|
||||||
parseOpts.plugins.jsx = true;
|
parseOpts.plugins.jsx = true;
|
||||||
parseOpts.plugins.flow = true;
|
parseOpts.plugins.flow = true;
|
||||||
}
|
|
||||||
|
|
||||||
var ast = acorn.parse(code, parseOpts);
|
|
||||||
|
|
||||||
estraverse.attachComments(ast, comments, tokens);
|
|
||||||
|
|
||||||
ast = normalizeAst(ast, comments, tokens);
|
|
||||||
|
|
||||||
if (callback) {
|
|
||||||
return callback(ast);
|
|
||||||
} else {
|
|
||||||
return ast;
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
if (!err._babel) {
|
|
||||||
err._babel = true;
|
|
||||||
|
|
||||||
var message = err.message = `${opts.filename}: ${err.message}`;
|
|
||||||
|
|
||||||
var loc = err.loc;
|
|
||||||
if (loc) {
|
|
||||||
err.codeFrame = codeFrame(code, loc.line, loc.column + 1, opts);
|
|
||||||
message += "\n" + err.codeFrame;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (err.stack) {
|
|
||||||
var newStack = err.stack.replace(err.message, message);
|
|
||||||
try {
|
|
||||||
err.stack = newStack;
|
|
||||||
} catch (e) {
|
|
||||||
// `err.stack` may be a readonly property in some environments
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
throw err;
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
var ast = acorn.parse(code, parseOpts);
|
||||||
|
|
||||||
|
estraverse.attachComments(ast, comments, tokens);
|
||||||
|
ast = normalizeAst(ast, comments, tokens);
|
||||||
|
return ast;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function all(code, opts = {}) {
|
||||||
|
opts.allowHashBang = true;
|
||||||
|
opts.sourceType = "module";
|
||||||
|
opts.ecmaVersion = Infinity;
|
||||||
|
opts.plugins = {
|
||||||
|
flow: true,
|
||||||
|
jsx: true
|
||||||
|
};
|
||||||
|
opts.features = {};
|
||||||
|
|
||||||
|
for (var key in transform.pipeline.transformers) {
|
||||||
|
opts.features[key] = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return acorn.parse(code, opts);
|
||||||
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import resolveRc from "../../tools/resolve-rc";
|
|||||||
import sourceMap from "source-map";
|
import sourceMap from "source-map";
|
||||||
import transform from "./../index";
|
import transform from "./../index";
|
||||||
import generate from "../../generation";
|
import generate from "../../generation";
|
||||||
|
import codeFrame from "../../helpers/code-frame";
|
||||||
import defaults from "lodash/object/defaults";
|
import defaults from "lodash/object/defaults";
|
||||||
import includes from "lodash/collection/includes";
|
import includes from "lodash/collection/includes";
|
||||||
import traverse from "../../traversal";
|
import traverse from "../../traversal";
|
||||||
@@ -236,48 +237,6 @@ export default class File {
|
|||||||
this.transformerStack = stack.concat(secondaryStack);
|
this.transformerStack = stack.concat(secondaryStack);
|
||||||
}
|
}
|
||||||
|
|
||||||
getModuleFormatter(type: string) {
|
|
||||||
var ModuleFormatter = isFunction(type) ? type : moduleFormatters[type];
|
|
||||||
|
|
||||||
if (!ModuleFormatter) {
|
|
||||||
var loc = util.resolveRelative(type);
|
|
||||||
if (loc) ModuleFormatter = require(loc);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!ModuleFormatter) {
|
|
||||||
throw new ReferenceError(`Unknown module formatter type ${JSON.stringify(type)}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new ModuleFormatter(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
parseInputSourceMap(code: string) {
|
|
||||||
var opts = this.opts;
|
|
||||||
|
|
||||||
if (opts.inputSourceMap !== false) {
|
|
||||||
var inputMap = convertSourceMap.fromSource(code);
|
|
||||||
if (inputMap) {
|
|
||||||
opts.inputSourceMap = inputMap.toObject();
|
|
||||||
code = convertSourceMap.removeComments(code);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
parseShebang(code: string) {
|
|
||||||
var shebangMatch = shebangRegex.exec(code);
|
|
||||||
|
|
||||||
if (shebangMatch) {
|
|
||||||
this.shebang = shebangMatch[0];
|
|
||||||
|
|
||||||
// remove shebang
|
|
||||||
code = code.replace(shebangRegex, "");
|
|
||||||
}
|
|
||||||
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
set(key: string, val): any {
|
set(key: string, val): any {
|
||||||
return this.data[key] = val;
|
return this.data[key] = val;
|
||||||
};
|
};
|
||||||
@@ -370,13 +329,24 @@ export default class File {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var ref = util.template("helper-" + name);
|
var ref = util.template("helper-" + name);
|
||||||
ref._compact = true;
|
|
||||||
var uid = this.declarations[name] = this.scope.generateUidIdentifier(name);
|
var uid = this.declarations[name] = this.scope.generateUidIdentifier(name);
|
||||||
this.scope.push({
|
|
||||||
id: uid,
|
if (t.isFunctionExpression(ref) && !ref.id) {
|
||||||
init: ref,
|
ref.body._compact = true;
|
||||||
unique: true
|
ref._generated = true;
|
||||||
});
|
ref.id = uid;
|
||||||
|
ref.type = "FunctionDeclaration";
|
||||||
|
this.path.unshiftContainer("body", ref);
|
||||||
|
} else {
|
||||||
|
ref._compact = true;
|
||||||
|
this.scope.push({
|
||||||
|
id: uid,
|
||||||
|
init: ref,
|
||||||
|
unique: true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return uid;
|
return uid;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -387,110 +357,6 @@ export default class File {
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
addCode(code: string) {
|
|
||||||
code = (code || "") + "";
|
|
||||||
code = this.parseInputSourceMap(code);
|
|
||||||
this.code = code;
|
|
||||||
return this.parseShebang(code);
|
|
||||||
}
|
|
||||||
|
|
||||||
shouldIgnore() {
|
|
||||||
var opts = this.opts;
|
|
||||||
return util.shouldIgnore(opts.filename, opts.ignore, opts.only);
|
|
||||||
}
|
|
||||||
|
|
||||||
parse(code: string) {
|
|
||||||
if (this.shouldIgnore()) {
|
|
||||||
return {
|
|
||||||
metadata: {},
|
|
||||||
code: code,
|
|
||||||
map: null,
|
|
||||||
ast: null
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
code = this.addCode(code);
|
|
||||||
|
|
||||||
var opts = this.opts;
|
|
||||||
|
|
||||||
//
|
|
||||||
|
|
||||||
var parseOpts = {
|
|
||||||
highlightCode: opts.highlightCode,
|
|
||||||
nonStandard: opts.nonStandard,
|
|
||||||
filename: opts.filename,
|
|
||||||
plugins: {}
|
|
||||||
};
|
|
||||||
|
|
||||||
var features = parseOpts.features = {};
|
|
||||||
for (var key in this.transformers) {
|
|
||||||
var transformer = this.transformers[key];
|
|
||||||
features[key] = transformer.canTransform();
|
|
||||||
}
|
|
||||||
|
|
||||||
parseOpts.looseModules = this.isLoose("es6.modules");
|
|
||||||
parseOpts.strictMode = features.strict;
|
|
||||||
parseOpts.sourceType = "module";
|
|
||||||
|
|
||||||
this.log.debug("Parse start");
|
|
||||||
|
|
||||||
//
|
|
||||||
|
|
||||||
return parse(parseOpts, code, (tree) => {
|
|
||||||
this.log.debug("Parse stop");
|
|
||||||
this.transform(tree);
|
|
||||||
return this.generate();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
setAst(ast) {
|
|
||||||
this.path = TraversalPath.get(null, null, ast, ast, "program", this);
|
|
||||||
this.scope = this.path.scope;
|
|
||||||
this.ast = ast;
|
|
||||||
|
|
||||||
this.path.traverse({
|
|
||||||
enter(node, parent, scope) {
|
|
||||||
if (this.isScope()) {
|
|
||||||
for (var key in scope.bindings) {
|
|
||||||
scope.bindings[key].setTypeAnnotation();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
transform(ast) {
|
|
||||||
this.log.debug("Start set AST");
|
|
||||||
this.setAst(ast);
|
|
||||||
this.log.debug("End set AST");
|
|
||||||
|
|
||||||
this.log.debug("Start prepass");
|
|
||||||
this.checkPath(this.path);
|
|
||||||
this.log.debug("End prepass");
|
|
||||||
|
|
||||||
this.log.debug("Start module formatter init");
|
|
||||||
var modFormatter = this.moduleFormatter = this.getModuleFormatter(this.opts.modules);
|
|
||||||
if (modFormatter.init && this.transformers["es6.modules"].canTransform()) {
|
|
||||||
modFormatter.init();
|
|
||||||
}
|
|
||||||
this.log.debug("End module formatter init");
|
|
||||||
|
|
||||||
this.call("pre");
|
|
||||||
each(this.transformerStack, function (pass) {
|
|
||||||
pass.transform();
|
|
||||||
});
|
|
||||||
this.call("post");
|
|
||||||
}
|
|
||||||
|
|
||||||
call(key: string) {
|
|
||||||
var stack = this.transformerStack;
|
|
||||||
for (var i = 0; i < stack.length; i++) {
|
|
||||||
var transformer = stack[i].transformer;
|
|
||||||
var fn = transformer[key];
|
|
||||||
if (fn) fn(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
checkPath(path) {
|
checkPath(path) {
|
||||||
if (Array.isArray(path)) {
|
if (Array.isArray(path)) {
|
||||||
for (var i = 0; i < path.length; i++) {
|
for (var i = 0; i < path.length; i++) {
|
||||||
@@ -530,6 +396,178 @@ export default class File {
|
|||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
getModuleFormatter(type: string) {
|
||||||
|
var ModuleFormatter = isFunction(type) ? type : moduleFormatters[type];
|
||||||
|
|
||||||
|
if (!ModuleFormatter) {
|
||||||
|
var loc = util.resolveRelative(type);
|
||||||
|
if (loc) ModuleFormatter = require(loc);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ModuleFormatter) {
|
||||||
|
throw new ReferenceError(`Unknown module formatter type ${JSON.stringify(type)}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ModuleFormatter(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
parse(code: string) {
|
||||||
|
var opts = this.opts;
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
var parseOpts = {
|
||||||
|
highlightCode: opts.highlightCode,
|
||||||
|
nonStandard: opts.nonStandard,
|
||||||
|
filename: opts.filename,
|
||||||
|
plugins: {}
|
||||||
|
};
|
||||||
|
|
||||||
|
var features = parseOpts.features = {};
|
||||||
|
for (var key in this.transformers) {
|
||||||
|
var transformer = this.transformers[key];
|
||||||
|
features[key] = transformer.canTransform();
|
||||||
|
}
|
||||||
|
|
||||||
|
parseOpts.looseModules = this.isLoose("es6.modules");
|
||||||
|
parseOpts.strictMode = features.strict;
|
||||||
|
parseOpts.sourceType = "module";
|
||||||
|
|
||||||
|
this.log.debug("Parse start");
|
||||||
|
var tree = parse(code, parseOpts);
|
||||||
|
this.log.debug("Parse stop");
|
||||||
|
return tree;
|
||||||
|
}
|
||||||
|
|
||||||
|
_addAst(ast) {
|
||||||
|
this.path = TraversalPath.get(null, null, ast, ast, "program", this);
|
||||||
|
this.scope = this.path.scope;
|
||||||
|
this.ast = ast;
|
||||||
|
|
||||||
|
this.path.traverse({
|
||||||
|
enter(node, parent, scope) {
|
||||||
|
if (this.isScope()) {
|
||||||
|
for (var key in scope.bindings) {
|
||||||
|
scope.bindings[key].setTypeAnnotation();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
addAst(ast) {
|
||||||
|
this.log.debug("Start set AST");
|
||||||
|
this._addAst(ast);
|
||||||
|
this.log.debug("End set AST");
|
||||||
|
|
||||||
|
this.log.debug("Start prepass");
|
||||||
|
this.checkPath(this.path);
|
||||||
|
this.log.debug("End prepass");
|
||||||
|
|
||||||
|
this.log.debug("Start module formatter init");
|
||||||
|
var modFormatter = this.moduleFormatter = this.getModuleFormatter(this.opts.modules);
|
||||||
|
if (modFormatter.init && this.transformers["es6.modules"].canTransform()) {
|
||||||
|
modFormatter.init();
|
||||||
|
}
|
||||||
|
this.log.debug("End module formatter init");
|
||||||
|
|
||||||
|
this.call("pre");
|
||||||
|
each(this.transformerStack, function (pass) {
|
||||||
|
pass.transform();
|
||||||
|
});
|
||||||
|
this.call("post");
|
||||||
|
}
|
||||||
|
|
||||||
|
wrap(code, callback) {
|
||||||
|
try {
|
||||||
|
if (this.shouldIgnore()) {
|
||||||
|
return {
|
||||||
|
metadata: {},
|
||||||
|
code: code,
|
||||||
|
map: null,
|
||||||
|
ast: null
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
callback();
|
||||||
|
|
||||||
|
return this.generate();
|
||||||
|
} catch (err) {
|
||||||
|
if (err._babel) {
|
||||||
|
throw err;
|
||||||
|
} else {
|
||||||
|
err._babel = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
var message = err.message = `${this.opts.filename}: ${err.message}`;
|
||||||
|
|
||||||
|
var loc = err.loc;
|
||||||
|
if (loc) {
|
||||||
|
err.codeFrame = codeFrame(code, loc.line, loc.column + 1, this.opts);
|
||||||
|
message += "\n" + err.codeFrame;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (err.stack) {
|
||||||
|
var newStack = err.stack.replace(err.message, message);
|
||||||
|
try {
|
||||||
|
err.stack = newStack;
|
||||||
|
} catch (e) {
|
||||||
|
// `err.stack` may be a readonly property in some environments
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
addCode(code: string, parseCode?) {
|
||||||
|
code = (code || "") + "";
|
||||||
|
code = this.parseInputSourceMap(code);
|
||||||
|
this.code = code;
|
||||||
|
|
||||||
|
if (parseCode) {
|
||||||
|
this.parseShebang();
|
||||||
|
this.addAst(this.parse(this.code));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
shouldIgnore() {
|
||||||
|
var opts = this.opts;
|
||||||
|
return util.shouldIgnore(opts.filename, opts.ignore, opts.only);
|
||||||
|
}
|
||||||
|
|
||||||
|
call(key: string) {
|
||||||
|
var stack = this.transformerStack;
|
||||||
|
for (var i = 0; i < stack.length; i++) {
|
||||||
|
var transformer = stack[i].transformer;
|
||||||
|
var fn = transformer[key];
|
||||||
|
if (fn) fn(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
parseInputSourceMap(code: string) {
|
||||||
|
var opts = this.opts;
|
||||||
|
|
||||||
|
if (opts.inputSourceMap !== false) {
|
||||||
|
var inputMap = convertSourceMap.fromSource(code);
|
||||||
|
if (inputMap) {
|
||||||
|
opts.inputSourceMap = inputMap.toObject();
|
||||||
|
code = convertSourceMap.removeComments(code);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
parseShebang() {
|
||||||
|
var shebangMatch = shebangRegex.exec(this.code);
|
||||||
|
if (shebangMatch) {
|
||||||
|
this.shebang = shebangMatch[0];
|
||||||
|
this.code = this.code.replace(shebangRegex, "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
generate(): {
|
generate(): {
|
||||||
usedHelpers?: Array<string>;
|
usedHelpers?: Array<string>;
|
||||||
code: string;
|
code: string;
|
||||||
|
|||||||
@@ -57,16 +57,19 @@ export default class TransformerPipeline {
|
|||||||
|
|
||||||
transform(code: string, opts?: Object) {
|
transform(code: string, opts?: Object) {
|
||||||
var file = new File(opts, this);
|
var file = new File(opts, this);
|
||||||
return file.parse(code);
|
return file.wrap(code, function () {
|
||||||
|
file.addCode(code, true);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
transformFromAst(ast, code, opts) {
|
transformFromAst(ast, code, opts) {
|
||||||
ast = normalizeAst(ast);
|
ast = normalizeAst(ast);
|
||||||
|
|
||||||
var file = new File(opts, this);
|
var file = new File(opts, this);
|
||||||
file.addCode(code);
|
return file.wrap(code, function () {
|
||||||
file.transform(ast);
|
file.addCode(code);
|
||||||
return file.generate();
|
file.addAst(ast);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
_ensureTransformerNames(type: string, rawKeys: Array<string>) {
|
_ensureTransformerNames(type: string, rawKeys: Array<string>) {
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
"es6.symbols": "es6.spec.symbols",
|
"es6.symbols": "es6.spec.symbols",
|
||||||
"es6.blockScopingTDZ": "es6.spec.blockScoping",
|
"es6.blockScopingTDZ": "es6.spec.blockScoping",
|
||||||
|
|
||||||
"minification.deadCodeElimination": "utility.deadCodeElimination",
|
"utility.deadCodeElimination": "minification.deadCodeElimination",
|
||||||
"minification.removeConsoleCalls": "utility.removeConsole",
|
"minification.removeConsoleCalls": "utility.removeConsole",
|
||||||
"minification.removeDebugger": "utility.removeDebugger"
|
"minification.removeDebugger": "utility.removeDebugger"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,11 +2,7 @@ import * as t from "../../../types";
|
|||||||
|
|
||||||
export function MemberExpression(node) {
|
export function MemberExpression(node) {
|
||||||
var prop = node.property;
|
var prop = node.property;
|
||||||
if (node.computed && t.isLiteral(prop) && t.isValidIdentifier(prop.value)) {
|
if (!node.computed && t.isIdentifier(prop) && !t.isValidIdentifier(prop.name)) {
|
||||||
// foo["bar"] => foo.bar
|
|
||||||
node.property = t.identifier(prop.value);
|
|
||||||
node.computed = false;
|
|
||||||
} else if (!node.computed && t.isIdentifier(prop) && !t.isValidIdentifier(prop.name)) {
|
|
||||||
// foo.default -> foo["default"]
|
// foo.default -> foo["default"]
|
||||||
node.property = t.literal(prop.name);
|
node.property = t.literal(prop.name);
|
||||||
node.computed = true;
|
node.computed = true;
|
||||||
|
|||||||
@@ -2,11 +2,7 @@ import * as t from "../../../types";
|
|||||||
|
|
||||||
export function Property(node) {
|
export function Property(node) {
|
||||||
var key = node.key;
|
var key = node.key;
|
||||||
if (t.isLiteral(key) && t.isValidIdentifier(key.value)) {
|
if (!node.computed && t.isIdentifier(key) && !t.isValidIdentifier(key.name)) {
|
||||||
// "foo": "bar" -> foo: "bar"
|
|
||||||
node.key = t.identifier(key.value);
|
|
||||||
node.computed = false;
|
|
||||||
} else if (!node.computed && t.isIdentifier(key) && !t.isValidIdentifier(key.name)) {
|
|
||||||
// default: "bar" -> "default": "bar"
|
// default: "bar" -> "default": "bar"
|
||||||
node.key = t.literal(key.name);
|
node.key = t.literal(key.name);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -96,10 +96,6 @@ var verifyConstructorVisitor = traverse.explode({
|
|||||||
if (state.hasSuper && !state.hasBareSuper) {
|
if (state.hasSuper && !state.hasBareSuper) {
|
||||||
throw this.errorWithNode("'this' is not allowed before super()");
|
throw this.errorWithNode("'this' is not allowed before super()");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state.isNativeSuper) {
|
|
||||||
return state.nativeSuperRef;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -154,15 +150,6 @@ class ClassTransformer {
|
|||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
var superClass = this.node.superClass;
|
|
||||||
this.isNativeSuper = superClass && t.isIdentifier(superClass) && t.NATIVE_TYPE_NAMES.indexOf(superClass.name) >= 0;
|
|
||||||
|
|
||||||
if (this.isNativeSuper) {
|
|
||||||
this.nativeSuperRef = this.scope.generateUidIdentifier("this");
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
|
|
||||||
var body = this.body;
|
var body = this.body;
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -234,12 +221,6 @@ class ClassTransformer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.isNativeSuper) {
|
|
||||||
// we've determined this is inheriting from a native class so return the constructed
|
|
||||||
// instance
|
|
||||||
constructorBody.body.push(t.returnStatement(this.nativeSuperRef));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.className) {
|
if (this.className) {
|
||||||
// named class with only a constructor
|
// named class with only a constructor
|
||||||
if (body.length === 1) return t.toExpression(body[0]);
|
if (body.length === 1) return t.toExpression(body[0]);
|
||||||
@@ -344,9 +325,7 @@ class ClassTransformer {
|
|||||||
if (!this.hasConstructor && this.hasSuper) {
|
if (!this.hasConstructor && this.hasSuper) {
|
||||||
var helperName = "class-super-constructor-call";
|
var helperName = "class-super-constructor-call";
|
||||||
if (this.isLoose) helperName += "-loose";
|
if (this.isLoose) helperName += "-loose";
|
||||||
if (this.isNativeSuper) helperName = "class-super-native-constructor-call";
|
|
||||||
constructorBody.body.push(util.template(helperName, {
|
constructorBody.body.push(util.template(helperName, {
|
||||||
NATIVE_REF: this.nativeSuperRef,
|
|
||||||
CLASS_NAME: this.classRef,
|
CLASS_NAME: this.classRef,
|
||||||
SUPER_NAME: this.superName
|
SUPER_NAME: this.superName
|
||||||
}, true));
|
}, true));
|
||||||
@@ -475,12 +454,10 @@ class ClassTransformer {
|
|||||||
|
|
||||||
verifyConstructor(path: TraversalPath) {
|
verifyConstructor(path: TraversalPath) {
|
||||||
var state = {
|
var state = {
|
||||||
nativeSuperRef: this.nativeSuperRef,
|
hasBareSuper: false,
|
||||||
isNativeSuper: this.isNativeSuper,
|
bareSuper: null,
|
||||||
hasBareSuper: false,
|
hasSuper: this.hasSuper,
|
||||||
bareSuper: null,
|
file: this.file
|
||||||
hasSuper: this.hasSuper,
|
|
||||||
file: this.file
|
|
||||||
};
|
};
|
||||||
|
|
||||||
path.get("value").traverse(verifyConstructorVisitor, state);
|
path.get("value").traverse(verifyConstructorVisitor, state);
|
||||||
@@ -490,22 +467,7 @@ class ClassTransformer {
|
|||||||
if (!state.hasBareSuper && this.hasSuper) {
|
if (!state.hasBareSuper && this.hasSuper) {
|
||||||
throw path.errorWithNode("Derived constructor must call super()");
|
throw path.errorWithNode("Derived constructor must call super()");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (this.isNativeSuper && this.bareSuper) {
|
|
||||||
this.bareSuper.replaceWithMultiple([
|
|
||||||
t.variableDeclaration("var", [
|
|
||||||
t.variableDeclarator(this.nativeSuperRef, t.newExpression(this.superName, this.bareSuper.node.arguments))
|
|
||||||
]),
|
|
||||||
|
|
||||||
t.expressionStatement(t.assignmentExpression(
|
|
||||||
"=",
|
|
||||||
t.memberExpression(this.nativeSuperRef, t.identifier("__proto__")),
|
|
||||||
t.memberExpression(this.classRef, t.identifier("prototype"))
|
|
||||||
)),
|
|
||||||
t.expressionStatement(this.nativeSuperRef)
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Push a method to its respective mutatorMap.
|
* Push a method to its respective mutatorMap.
|
||||||
@@ -605,10 +567,6 @@ class ClassTransformer {
|
|||||||
fnPath.scope.rename(this.classRef.name);
|
fnPath.scope.rename(this.classRef.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.isNativeSuper) {
|
|
||||||
fnPath.traverse(constructorVisitor, this.nativeSuperRef);
|
|
||||||
}
|
|
||||||
|
|
||||||
var construct = this.constructor;
|
var construct = this.constructor;
|
||||||
var fn = method.value;
|
var fn = method.value;
|
||||||
|
|
||||||
|
|||||||
@@ -16,27 +16,13 @@ function loose(node, body, objId) {
|
|||||||
|
|
||||||
function spec(node, body, objId, initProps, file) {
|
function spec(node, body, objId, initProps, file) {
|
||||||
var props = node.properties;
|
var props = node.properties;
|
||||||
var prop, key;
|
|
||||||
|
|
||||||
// normalize key
|
|
||||||
|
|
||||||
for (var i = 0; i < props.length; i++) {
|
|
||||||
prop = props[i];
|
|
||||||
if (prop.kind !== "init") continue;
|
|
||||||
|
|
||||||
key = prop.key;
|
|
||||||
|
|
||||||
if (!prop.computed && t.isIdentifier(key)) {
|
|
||||||
prop.key = t.literal(key.name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// add all non-computed properties and `__proto__` properties to the initializer
|
// add all non-computed properties and `__proto__` properties to the initializer
|
||||||
|
|
||||||
var broken = false;
|
var broken = false;
|
||||||
|
|
||||||
for (i = 0; i < props.length; i++) {
|
for (let i = 0; i < props.length; i++) {
|
||||||
prop = props[i];
|
let prop = props[i];
|
||||||
|
|
||||||
if (prop.computed) {
|
if (prop.computed) {
|
||||||
broken = true;
|
broken = true;
|
||||||
@@ -51,24 +37,17 @@ function spec(node, body, objId, initProps, file) {
|
|||||||
// add a simple assignment for all Symbol member expressions due to symbol polyfill limitations
|
// add a simple assignment for all Symbol member expressions due to symbol polyfill limitations
|
||||||
// otherwise use Object.defineProperty
|
// otherwise use Object.defineProperty
|
||||||
|
|
||||||
for (i = 0; i < props.length; i++) {
|
for (let i = 0; i < props.length; i++) {
|
||||||
prop = props[i];
|
let prop = props[i];
|
||||||
if (!prop) continue;
|
if (!prop) continue;
|
||||||
|
|
||||||
key = prop.key;
|
let key = prop.key;
|
||||||
var bodyNode;
|
if (t.isIdentifier(key) && !prop.computed) {
|
||||||
|
key = t.literal(key.name);
|
||||||
if (prop.computed && t.isMemberExpression(key) && t.isIdentifier(key.object, { name: "Symbol" })) {
|
|
||||||
// { [Symbol.iterator]: "foo" }
|
|
||||||
bodyNode = t.assignmentExpression(
|
|
||||||
"=",
|
|
||||||
t.memberExpression(objId, key, true),
|
|
||||||
prop.value
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
bodyNode = t.callExpression(file.addHelper("define-property"), [objId, key, prop.value]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var bodyNode = t.callExpression(file.addHelper("define-property"), [objId, key, prop.value]);
|
||||||
|
|
||||||
body.push(t.expressionStatement(bodyNode));
|
body.push(t.expressionStatement(bodyNode));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,3 +33,5 @@ export function BinaryExpression(node, parent, scope, file) {
|
|||||||
export function VariableDeclaration(node) {
|
export function VariableDeclaration(node) {
|
||||||
if (node._generated) this.skip();
|
if (node._generated) this.skip();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export { VariableDeclaration as FunctionDeclaration };
|
||||||
|
|||||||
@@ -18,15 +18,7 @@ function returnBlock(expr) {
|
|||||||
// looks for and replaces tail recursion calls
|
// looks for and replaces tail recursion calls
|
||||||
var firstPass = {
|
var firstPass = {
|
||||||
enter(node, parent, scope, state) {
|
enter(node, parent, scope, state) {
|
||||||
if (this.isIfStatement()) {
|
if (this.isReturnStatement()) {
|
||||||
if (this.get("alternate").isReturnStatement()) {
|
|
||||||
t.ensureBlock(node, "alternate");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.get("consequent").isReturnStatement()) {
|
|
||||||
t.ensureBlock(node, "consequent");
|
|
||||||
}
|
|
||||||
} else if (this.isReturnStatement()) {
|
|
||||||
this.skip();
|
this.skip();
|
||||||
return state.subTransform(node.argument);
|
return state.subTransform(node.argument);
|
||||||
} else if (t.isTryStatement(parent)) {
|
} else if (t.isTryStatement(parent)) {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
export default {
|
export default {
|
||||||
_modules: require("./internal/modules"),
|
_modules: require("./internal/modules"),
|
||||||
|
"minification.deadCodeElimination": require("./minification/dead-code-elimination"),
|
||||||
|
|
||||||
"es7.classProperties": require("./es7/class-properties"),
|
"es7.classProperties": require("./es7/class-properties"),
|
||||||
"es7.trailingFunctionCommas": require("./es7/trailing-function-commas"),
|
"es7.trailingFunctionCommas": require("./es7/trailing-function-commas"),
|
||||||
@@ -113,7 +114,9 @@ export default {
|
|||||||
|
|
||||||
"utility.inlineEnvironmentVariables": require("./utility/inline-environment-variables"),
|
"utility.inlineEnvironmentVariables": require("./utility/inline-environment-variables"),
|
||||||
"utility.inlineExpressions": require("./utility/inline-expressions"),
|
"utility.inlineExpressions": require("./utility/inline-expressions"),
|
||||||
"utility.deadCodeElimination": require("./utility/dead-code-elimination"),
|
|
||||||
|
"minification.memberExpressionLiterals": require("./minification/member-expression-literals"),
|
||||||
|
"minification.propertyLiterals": require("./minification/property-literals"),
|
||||||
|
|
||||||
jscript: require("./other/jscript"),
|
jscript: require("./other/jscript"),
|
||||||
flow: require("./other/flow")
|
flow: require("./other/flow")
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
import * as t from "../../../types";
|
||||||
|
|
||||||
|
export var metadata = {
|
||||||
|
optional: true
|
||||||
|
};
|
||||||
|
|
||||||
|
export function MemberExpression(node) {
|
||||||
|
var prop = node.property;
|
||||||
|
if (node.computed && t.isLiteral(prop) && t.isValidIdentifier(prop.value)) {
|
||||||
|
// foo["bar"] => foo.bar
|
||||||
|
node.property = t.identifier(prop.value);
|
||||||
|
node.computed = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
import * as t from "../../../types";
|
||||||
|
|
||||||
|
export var metadata = {
|
||||||
|
optional: true
|
||||||
|
};
|
||||||
|
|
||||||
|
export function Property(node) {
|
||||||
|
var key = node.key;
|
||||||
|
if (t.isLiteral(key) && t.isValidIdentifier(key.value)) {
|
||||||
|
// "foo": "bar" -> foo: "bar"
|
||||||
|
node.key = t.identifier(key.value);
|
||||||
|
node.computed = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,6 +9,6 @@ export var Program = {
|
|||||||
enter(ast) {
|
enter(ast) {
|
||||||
regenerator.transform(ast);
|
regenerator.transform(ast);
|
||||||
this.stop();
|
this.stop();
|
||||||
return ast; // force a checkPath, this really needs to be optimised
|
this.checkSelf();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ import isBoolean from "lodash/lang/isBoolean";
|
|||||||
import isNumber from "lodash/lang/isNumber";
|
import isNumber from "lodash/lang/isNumber";
|
||||||
import isRegExp from "lodash/lang/isRegExp";
|
import isRegExp from "lodash/lang/isRegExp";
|
||||||
import isString from "lodash/lang/isString";
|
import isString from "lodash/lang/isString";
|
||||||
|
import codeFrame from "../../helpers/code-frame";
|
||||||
|
import { all as parse } from "../../helpers/parse";
|
||||||
import traverse from "../index";
|
import traverse from "../index";
|
||||||
import includes from "lodash/collection/includes";
|
import includes from "lodash/collection/includes";
|
||||||
import assign from "lodash/object/assign";
|
import assign from "lodash/object/assign";
|
||||||
@@ -116,7 +118,7 @@ export default class TraversalPath {
|
|||||||
} else if (this.isStatementOrBlock()) {
|
} else if (this.isStatementOrBlock()) {
|
||||||
if (this.node) nodes.push(this.node);
|
if (this.node) nodes.push(this.node);
|
||||||
this.container[this.key] = t.blockStatement(nodes);
|
this.container[this.key] = t.blockStatement(nodes);
|
||||||
this.checkPaths(this);
|
this.checkSelf();
|
||||||
} else {
|
} else {
|
||||||
throw new Error("We don't know what to do with this node type. We were previously a Statement but we can't fit in here?");
|
throw new Error("We don't know what to do with this node type. We were previously a Statement but we can't fit in here?");
|
||||||
}
|
}
|
||||||
@@ -214,7 +216,7 @@ export default class TraversalPath {
|
|||||||
} else if (this.isStatementOrBlock()) {
|
} else if (this.isStatementOrBlock()) {
|
||||||
if (this.node) nodes.unshift(this.node);
|
if (this.node) nodes.unshift(this.node);
|
||||||
this.container[this.key] = t.blockStatement(nodes);
|
this.container[this.key] = t.blockStatement(nodes);
|
||||||
this.checkPaths(this);
|
this.checkSelf();
|
||||||
} else {
|
} else {
|
||||||
throw new Error("We don't know what to do with this node type. We were previously a Statement but we can't fit in here?");
|
throw new Error("We don't know what to do with this node type. We were previously a Statement but we can't fit in here?");
|
||||||
}
|
}
|
||||||
@@ -476,7 +478,29 @@ export default class TraversalPath {
|
|||||||
* Description
|
* Description
|
||||||
*/
|
*/
|
||||||
|
|
||||||
replaceWith(replacement, arraysAllowed) {
|
replaceWithSourceString(replacement) {
|
||||||
|
try {
|
||||||
|
replacement = `(${replacement})`;
|
||||||
|
replacement = parse(code);
|
||||||
|
} catch (err) {
|
||||||
|
var loc = err.loc;
|
||||||
|
if (loc) {
|
||||||
|
err.message += " - make sure this is an expression.";
|
||||||
|
err.message += "\n" + codeFrame(replacement, loc.line, loc.column + 1);
|
||||||
|
}
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
|
||||||
|
replacement = replacement.body[0].expression;
|
||||||
|
traverse.removeProperties(replacement);
|
||||||
|
return this.replaceWith(replacement);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description
|
||||||
|
*/
|
||||||
|
|
||||||
|
replaceWith(replacement, whateverAllowed) {
|
||||||
if (this.removed) {
|
if (this.removed) {
|
||||||
throw new Error("You can't replace this node, we've already removed it");
|
throw new Error("You can't replace this node, we've already removed it");
|
||||||
}
|
}
|
||||||
@@ -485,14 +509,33 @@ export default class TraversalPath {
|
|||||||
throw new Error("You passed `path.replaceWith()` a falsy node, use `path.remove()` instead");
|
throw new Error("You passed `path.replaceWith()` a falsy node, use `path.remove()` instead");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// normalise inserting an entire AST
|
||||||
|
if (t.isProgram(replacement)) {
|
||||||
|
replacement = replacement.body;
|
||||||
|
}
|
||||||
|
|
||||||
if (Array.isArray(replacement)) {
|
if (Array.isArray(replacement)) {
|
||||||
if (arraysAllowed) {
|
if (whateverAllowed) {
|
||||||
return this.replaceWithMultiple(replacement);
|
return this.replaceWithMultiple(replacement);
|
||||||
} else {
|
} else {
|
||||||
throw new Error("Don't use `path.replaceWith()` with an array of nodes, use `path.replaceWithMultiple()`");
|
throw new Error("Don't use `path.replaceWith()` with an array of nodes, use `path.replaceWithMultiple()`");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (typeof replacement === "string") {
|
||||||
|
if (whateverAllowed) {
|
||||||
|
return this.replaceWithSourceString(replacement);
|
||||||
|
} else {
|
||||||
|
throw new Error("Don't use `path.replaceWith()` with a string, use `path.replaceWithSourceString()`");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// replacing a statement with an expression so wrap it in an expression statement
|
||||||
|
if (this.isPreviousType("Statement") && t.isExpression(replacement)) {
|
||||||
|
replacement = t.expressionStatement(replacement);
|
||||||
|
}
|
||||||
|
|
||||||
|
// replacing an expression with a statement so let's explode it
|
||||||
if (this.isPreviousType("Expression") && t.isStatement(replacement)) {
|
if (this.isPreviousType("Expression") && t.isStatement(replacement)) {
|
||||||
return this.replaceExpressionWithStatements([replacement]);
|
return this.replaceExpressionWithStatements([replacement]);
|
||||||
}
|
}
|
||||||
@@ -507,6 +550,14 @@ export default class TraversalPath {
|
|||||||
// potentially create new scope
|
// potentially create new scope
|
||||||
this.setScope();
|
this.setScope();
|
||||||
|
|
||||||
|
this.checkSelf();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description
|
||||||
|
*/
|
||||||
|
|
||||||
|
checkSelf() {
|
||||||
this.checkPaths(this);
|
this.checkPaths(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -74,8 +74,15 @@ var renameVisitor = explode({
|
|||||||
Identifier(node, parent, scope, state) {
|
Identifier(node, parent, scope, state) {
|
||||||
if (this.isReferenced() && node.name === state.oldName) {
|
if (this.isReferenced() && node.name === state.oldName) {
|
||||||
if (this.parentPath.isProperty() && this.key === "key" && parent.shorthand) {
|
if (this.parentPath.isProperty() && this.key === "key" && parent.shorthand) {
|
||||||
|
var value = t.identifier(state.newName);;
|
||||||
|
|
||||||
|
if (parent.value === state.binding) {
|
||||||
|
state.info.identifier = state.binding = value;
|
||||||
|
}
|
||||||
|
|
||||||
parent.shorthand = false;
|
parent.shorthand = false;
|
||||||
parent.value = t.identifier(state.newName);
|
parent.value = value;
|
||||||
|
parent.key = t.identifier(state.oldName);
|
||||||
} else {
|
} else {
|
||||||
node.name = state.newName;
|
node.name = state.newName;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -155,7 +155,7 @@ export function template(name: string, nodes?: Array<Object>, keepExpression?: b
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function parseTemplate(loc: string, code: string): Object {
|
export function parseTemplate(loc: string, code: string): Object {
|
||||||
var ast = parse({ filename: loc, looseModules: true }, code).program;
|
var ast = parse(code, { filename: loc, looseModules: true }).program;
|
||||||
ast = traverse.removeProperties(ast);
|
ast = traverse.removeProperties(ast);
|
||||||
return ast;
|
return ast;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } };
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||||
|
|
||||||
var Test = function Test() {
|
var Test = function Test() {
|
||||||
_classCallCheck(this, Test);
|
_classCallCheck(this, Test);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } };
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||||
|
|
||||||
var Test = function Test() {
|
var Test = function Test() {
|
||||||
_classCallCheck(this, Test);
|
_classCallCheck(this, Test);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } };
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||||
|
|
||||||
var Test = function Test() {
|
var Test = function Test() {
|
||||||
_classCallCheck(this, Test);
|
_classCallCheck(this, Test);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } };
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||||
|
|
||||||
var Test = function Test() {
|
var Test = function Test() {
|
||||||
_classCallCheck(this, Test);
|
_classCallCheck(this, Test);
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
obj["x"] = 2;
|
|
||||||
|
|
||||||
test.catch;
|
test.catch;
|
||||||
test.catch["foo"];
|
test.catch.foo;
|
||||||
test["catch"];
|
test["catch"];
|
||||||
test["catch"]["foo"];
|
test["catch"].foo;
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
obj.x = 2;
|
|
||||||
|
|
||||||
test["catch"];
|
test["catch"];
|
||||||
test["catch"].foo;
|
test["catch"].foo;
|
||||||
test["catch"];
|
test["catch"];
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var obj = {
|
var obj = {
|
||||||
test: "foob",
|
"test": "foob",
|
||||||
"!@#$": "foob",
|
"!@#$": "foob",
|
||||||
"33rd": "foob",
|
"33rd": "foob",
|
||||||
fooBar: "foob"
|
fooBar: "foob"
|
||||||
|
|||||||
@@ -1,17 +0,0 @@
|
|||||||
class Foo extends Array {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
class Bar extends Array {
|
|
||||||
constructor() {
|
|
||||||
super();
|
|
||||||
this.foo = "bar";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class Baz extends Array {
|
|
||||||
constructor() {
|
|
||||||
super();
|
|
||||||
(() => this)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
class Foo extends Array {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
class Bar extends Array {
|
|
||||||
constructor() {
|
|
||||||
super();
|
|
||||||
this.foo = "bar";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var foo = new Foo;
|
|
||||||
assert.ok(Array.isArray(foo));
|
|
||||||
foo.push(1);
|
|
||||||
foo.push(2);
|
|
||||||
assert.equal(foo[0], 1);
|
|
||||||
assert.equal(foo[1], 2);
|
|
||||||
assert.equal(foo.length, 2);
|
|
||||||
|
|
||||||
var bar = new Bar;
|
|
||||||
assert.ok(Array.isArray(bar));
|
|
||||||
assert.equal(bar.foo, "bar");
|
|
||||||
bar.push(1);
|
|
||||||
bar.push(2);
|
|
||||||
assert.equal(bar[0], 1);
|
|
||||||
assert.equal(bar[1], 2);
|
|
||||||
assert.equal(bar.length, 2);
|
|
||||||
@@ -1,53 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
|
|
||||||
var Foo = (function (_Array) {
|
|
||||||
function Foo() {
|
|
||||||
babelHelpers.classCallCheck(this, Foo);
|
|
||||||
|
|
||||||
if (_Array != null) {
|
|
||||||
var _this = new (babelHelpers.bind.apply(_Array, [null].concat(babelHelpers.slice.call(arguments))))();
|
|
||||||
|
|
||||||
_this.__proto__ = Foo.prototype;
|
|
||||||
return _this;
|
|
||||||
}
|
|
||||||
|
|
||||||
return _this;
|
|
||||||
}
|
|
||||||
|
|
||||||
babelHelpers.inherits(Foo, _Array);
|
|
||||||
return Foo;
|
|
||||||
})(Array);
|
|
||||||
|
|
||||||
var Bar = (function (_Array2) {
|
|
||||||
function Bar() {
|
|
||||||
babelHelpers.classCallCheck(this, Bar);
|
|
||||||
|
|
||||||
var _this2 = new _Array2();
|
|
||||||
|
|
||||||
_this2.__proto__ = Bar.prototype;
|
|
||||||
|
|
||||||
_this2.foo = "bar";
|
|
||||||
return _this2;
|
|
||||||
}
|
|
||||||
|
|
||||||
babelHelpers.inherits(Bar, _Array2);
|
|
||||||
return Bar;
|
|
||||||
})(Array);
|
|
||||||
|
|
||||||
var Baz = (function (_Array3) {
|
|
||||||
function Baz() {
|
|
||||||
babelHelpers.classCallCheck(this, Baz);
|
|
||||||
|
|
||||||
var _this3 = new _Array3();
|
|
||||||
|
|
||||||
_this3.__proto__ = Baz.prototype;
|
|
||||||
|
|
||||||
(function () {
|
|
||||||
return _this3;
|
|
||||||
});
|
|
||||||
return _this3;
|
|
||||||
}
|
|
||||||
|
|
||||||
babelHelpers.inherits(Baz, _Array3);
|
|
||||||
return Baz;
|
|
||||||
})(Array);
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } };
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||||
|
|
||||||
var _default = (function () {
|
var _default = (function () {
|
||||||
var _class = function _default() {
|
var _class = function _default() {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } };
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||||
|
|
||||||
var foo = 1;
|
var foo = 1;
|
||||||
var foo = 1,
|
var foo = 1,
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
System.register([], function (_export) {
|
System.register([], function (_export) {
|
||||||
var _default, Foo;
|
var _default, Foo;
|
||||||
|
|
||||||
var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } };
|
|
||||||
|
|
||||||
_export("default", foo);
|
_export("default", foo);
|
||||||
|
|
||||||
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||||
|
|
||||||
function foo() {}
|
function foo() {}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
System.register([], function (_export) {
|
System.register([], function (_export) {
|
||||||
var foo, foo2, foo3, foo4, foo5, foo6, foo8;
|
var foo, foo2, foo3, foo4, foo5, foo6, foo8;
|
||||||
|
|
||||||
var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } };
|
|
||||||
|
|
||||||
_export("foo7", foo7);
|
_export("foo7", foo7);
|
||||||
|
|
||||||
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||||
|
|
||||||
function foo7() {}
|
function foo7() {}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -2,4 +2,4 @@
|
|||||||
|
|
||||||
var _obj;
|
var _obj;
|
||||||
|
|
||||||
var obj = (_obj = {}, _obj.first = "first", _obj.second = "second", _obj);
|
var obj = (_obj = {}, _obj.first = "first", _obj["second"] = "second", _obj);
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var _foo;
|
var foo = babelHelpers.defineProperty({}, Symbol.iterator, "foobar");
|
||||||
|
|
||||||
var foo = (_foo = {}, _foo[Symbol.iterator] = "foobar", _foo);
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var _taggedTemplateLiteralLoose = function (strings, raw) { strings.raw = raw; return strings; };
|
function _taggedTemplateLiteralLoose(strings, raw) { strings.raw = raw; return strings; }
|
||||||
|
|
||||||
var foo = bar(_taggedTemplateLiteralLoose(["wow\na", "b ", ""], ["wow\\na", "b ", ""]), 42, _.foobar());
|
var foo = bar(_taggedTemplateLiteralLoose(["wow\na", "b ", ""], ["wow\\na", "b ", ""]), 42, _.foobar());
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var _taggedTemplateLiteral = function (strings, raw) { return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); };
|
function _taggedTemplateLiteral(strings, raw) { return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
||||||
|
|
||||||
var foo = bar(_taggedTemplateLiteral(["wow\na", "b ", ""], ["wow\\na", "b ", ""]), 42, _.foobar());
|
var foo = bar(_taggedTemplateLiteral(["wow\na", "b ", ""], ["wow\\na", "b ", ""]), 42, _.foobar());
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
foo["default"];
|
||||||
|
foo["import"];
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
foo["default"];
|
||||||
|
foo["import"];
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"optional": ["minification.memberExpressionLiterals"]
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
foo["bar"];
|
||||||
|
foo["foo"];
|
||||||
|
foo.bar;
|
||||||
|
foo.foo;
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
foo.bar;
|
||||||
|
foo.foo;
|
||||||
|
foo.bar;
|
||||||
|
foo.foo;
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
({
|
||||||
|
"default": null,
|
||||||
|
"import": null
|
||||||
|
});
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
({
|
||||||
|
"default": null,
|
||||||
|
"import": null
|
||||||
|
});
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"optional": ["minification.propertyLiterals"]
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
var obj = {
|
||||||
|
foo: "foo",
|
||||||
|
"bar": "bar"
|
||||||
|
};
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
var obj = {
|
||||||
|
foo: "foo",
|
||||||
|
bar: "bar"
|
||||||
|
};
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
var obj = {
|
||||||
|
search: function({search}) {
|
||||||
|
console.log(search);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
function search({search}) {
|
||||||
|
console.log(search);
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
var obj = {
|
||||||
|
search: function search(_ref) {
|
||||||
|
var _search = _ref.search;
|
||||||
|
|
||||||
|
console.log(_search);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
function search(_ref2) {
|
||||||
|
var search = _ref2.search;
|
||||||
|
|
||||||
|
console.log(search);
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var _defaults = function (obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; };
|
function _defaults(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; }
|
||||||
|
|
||||||
var _foo, _foo$bar, _foo$bar2;
|
var _foo, _foo$bar, _foo$bar2;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var _defaults = function (obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; };
|
function _defaults(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; }
|
||||||
|
|
||||||
_defaults(obj, bar);
|
_defaults(obj, bar);
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var _defaults = function (obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; };
|
function _defaults(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; }
|
||||||
|
|
||||||
var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } };
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||||
|
|
||||||
var _inherits = function (subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) _defaults(subClass, superClass); };
|
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) _defaults(subClass, superClass); }
|
||||||
|
|
||||||
var Foo = (function (_Bar) {
|
var Foo = (function (_Bar) {
|
||||||
function Foo() {
|
function Foo() {
|
||||||
@@ -18,4 +18,4 @@ var Foo = (function (_Bar) {
|
|||||||
_inherits(Foo, _Bar);
|
_inherits(Foo, _Bar);
|
||||||
|
|
||||||
return Foo;
|
return Foo;
|
||||||
})(Bar);
|
})(Bar);
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
var generate = require("../../lib/babel/generation");
|
var generate = require("../../lib/babel/generation");
|
||||||
var assert = require("assert");
|
var assert = require("assert");
|
||||||
var helper = require("./_helper");
|
var helper = require("./_helper");
|
||||||
var parse = require("../../lib/babel/helpers/parse");
|
var parse = require("../../lib/babel/helpers/parse").default;
|
||||||
var chai = require("chai");
|
var chai = require("chai");
|
||||||
var t = require("../../lib/babel/types");
|
var t = require("../../lib/babel/types");
|
||||||
var _ = require("lodash");
|
var _ = require("lodash");
|
||||||
@@ -26,7 +26,7 @@ _.each(helper.get("generation"), function (testSuite) {
|
|||||||
var expect = task.expect;
|
var expect = task.expect;
|
||||||
var actual = task.actual;
|
var actual = task.actual;
|
||||||
|
|
||||||
var actualAst = parse({
|
var actualAst = parse(actual.code, {
|
||||||
filename: actual.loc,
|
filename: actual.loc,
|
||||||
nonStandard: true,
|
nonStandard: true,
|
||||||
strictMode: false,
|
strictMode: false,
|
||||||
@@ -36,7 +36,7 @@ _.each(helper.get("generation"), function (testSuite) {
|
|||||||
"es7.asyncFunctions": true,
|
"es7.asyncFunctions": true,
|
||||||
"es7.exportExtensions": true
|
"es7.exportExtensions": true
|
||||||
}
|
}
|
||||||
}, actual.code);
|
});
|
||||||
var actualCode = generate(actualAst, task.options, actual.code).code;
|
var actualCode = generate(actualAst, task.options, actual.code).code;
|
||||||
|
|
||||||
chai.expect(actualCode).to.equal(expect.code, actual.loc + " !== " + expect.loc);
|
chai.expect(actualCode).to.equal(expect.code, actual.loc + " !== " + expect.loc);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
var assert = require("assert");
|
var assert = require("assert");
|
||||||
var util = require("../../lib/babel/util");
|
var util = require("../../lib/babel/util");
|
||||||
var parse = require("../../lib/babel/helpers/parse");
|
var parse = require("../../lib/babel/helpers/parse").default;
|
||||||
var t = require("../../lib/babel/types");
|
var t = require("../../lib/babel/types");
|
||||||
|
|
||||||
suite("util", function () {
|
suite("util", function () {
|
||||||
@@ -11,19 +11,18 @@ suite("util", function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("templates do not recurse", function () {
|
test("templates do not recurse", function () {
|
||||||
var key = __filename;
|
var key = __filename;
|
||||||
var KEY = parse({ loc: key }, "replacedKey").program.body[0].expression;
|
var KEY = parse("replacedKey").program.body[0].expression;
|
||||||
var VALUE = parse({ loc: key }, "+KEY").program.body[0].expression;
|
var VALUE = parse("+KEY").program.body[0].expression;
|
||||||
|
|
||||||
util.templates[key] = util.parseTemplate(key, "KEY = VALUE;");
|
util.templates[key] = util.parseTemplate(key, "KEY = VALUE;");
|
||||||
var result = util.template(key, {KEY: KEY, VALUE: VALUE});
|
var result = util.template(key, { KEY: KEY, VALUE: VALUE });
|
||||||
delete util.templates[key];
|
delete util.templates[key];
|
||||||
|
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
result.right.argument.name,
|
result.right.argument.name,
|
||||||
"KEY",
|
"KEY",
|
||||||
"template should not recurse into replaced nodes, " +
|
"template should not recurse into replaced nodes, replacing KEY inside VALUE"
|
||||||
"replacing KEY inside VALUE"
|
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user