Compare commits
34 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
253ea8cd18 | ||
|
|
d37bad3149 | ||
|
|
a2b912bc77 | ||
|
|
f1bfbe44e2 | ||
|
|
dbdd07d0b8 | ||
|
|
166909998e | ||
|
|
a8ec4c965c | ||
|
|
d2aff67c6c | ||
|
|
3353de225d | ||
|
|
203ebeef20 | ||
|
|
032cf990c3 | ||
|
|
16cdb43c67 | ||
|
|
6f622033c5 | ||
|
|
531d4f1937 | ||
|
|
f155bc249c | ||
|
|
452d0ef30e | ||
|
|
005754ba98 | ||
|
|
c3c4cf17e3 | ||
|
|
0866e5a403 | ||
|
|
15f5e658fc | ||
|
|
574e6da132 | ||
|
|
da6d27ed16 | ||
|
|
4e87809ff9 | ||
|
|
f4267aaab0 | ||
|
|
4f255d103a | ||
|
|
502cc13aed | ||
|
|
0a1154e6fd | ||
|
|
f5b3d72730 | ||
|
|
e9bcccffbd | ||
|
|
aaf4cbf06f | ||
|
|
5080534974 | ||
|
|
02cb397873 | ||
|
|
d9169a87ad | ||
|
|
f3b6f2fc61 |
30
CHANGELOG.md
30
CHANGELOG.md
@@ -13,6 +13,36 @@ _Note: Gaps between patch versions are faulty/broken releases._
|
||||
|
||||
See [CHANGELOG - 6to5](CHANGELOG-6to5.md) for the pre-4.0.0 version changelog.
|
||||
|
||||
## 5.2.6
|
||||
|
||||
* **Internal**
|
||||
* Fix transformer aliases being accidently set as deprecated ones.
|
||||
* Expose `Pipeline` as `TransformerPipeline` instead.
|
||||
|
||||
## 5.2.5
|
||||
|
||||
* **Bug Fix**
|
||||
* Fix `parse` API not adding all the correct pipeline transformers.
|
||||
|
||||
## 5.2.4
|
||||
|
||||
* **Bug Fix**
|
||||
* Fix race condition with the Node API being loaded awkwardly and not being able to initialise itself when used in the browser.
|
||||
* **Internal**
|
||||
* Expose `transform.pipeline`.
|
||||
|
||||
## 5.2.3
|
||||
|
||||
* **Bug Fix**
|
||||
* Fix plugin containers being called with an undefined import. Thanks [@timbur](https://github.com/timbur)!
|
||||
* Allow Flow object separators to be commas. Thanks [@monsanto](https://github.com/monsanto)!
|
||||
* Add missing `Statement` and `Declaration` node aliases to flow types.
|
||||
|
||||
## 5.2.2
|
||||
|
||||
* **Internal**
|
||||
* Allow `util.arrayify` to take arbitrary types and coerce it into an array.
|
||||
|
||||
## 5.2.1
|
||||
|
||||
* **Bug Fix**
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "babel-core",
|
||||
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
|
||||
"version": "5.2.1",
|
||||
"version": "5.2.6",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://babeljs.io/",
|
||||
"repository": "babel/babel",
|
||||
@@ -28,6 +28,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"ast-types": "~0.7.0",
|
||||
"bluebird": "^2.9.25",
|
||||
"chalk": "^1.0.0",
|
||||
"convert-source-map": "^1.1.0",
|
||||
"core-js": "^0.9.0",
|
||||
@@ -49,6 +50,7 @@
|
||||
"regenerator": "^0.8.20",
|
||||
"regexpu": "^1.1.2",
|
||||
"repeating": "^1.1.2",
|
||||
"resolve": "^1.1.6",
|
||||
"shebang-regex": "^1.0.0",
|
||||
"slash": "^1.0.0",
|
||||
"source-map": "^0.4.0",
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
{
|
||||
"name": "babel",
|
||||
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
|
||||
"version": "5.2.0",
|
||||
"version": "5.2.5",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://babeljs.io/",
|
||||
"repository": "babel/babel",
|
||||
"preferGlobal": true,
|
||||
"dependencies": {
|
||||
"babel-core": "^5.2.0",
|
||||
"babel-core": "^5.2.5",
|
||||
"chokidar": "^1.0.0",
|
||||
"commander": "^2.6.0",
|
||||
"convert-source-map": "^1.1.0",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "babel-runtime",
|
||||
"description": "babel selfContained runtime",
|
||||
"version": "5.2.0",
|
||||
"version": "5.2.5",
|
||||
"repository": "babel/babel",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"dependencies": {
|
||||
|
||||
@@ -322,7 +322,7 @@ pp.flow_parseObjectType = function (allowStatic) {
|
||||
}
|
||||
|
||||
pp.flow_objectTypeSemicolon = function () {
|
||||
if (!this.eat(tt.semi) && this.type !== tt.braceR) {
|
||||
if (!this.eat(tt.semi) && !this.eat(tt.comma) && this.type !== tt.braceR) {
|
||||
this.unexpected()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
require("./node");
|
||||
var transform = module.exports = require("../transformation");
|
||||
|
||||
transform.options = require("../transformation/file/options");
|
||||
|
||||
@@ -5,10 +5,12 @@ import * as util from "../util";
|
||||
import fs from "fs";
|
||||
|
||||
export { util, acorn, transform };
|
||||
export { pipeline } from "../transformation";
|
||||
export { canCompile } from "../util";
|
||||
|
||||
export { default as options } from "../transformation/file/options";
|
||||
export { default as Transformer } from "../transformation/transformer";
|
||||
export { default as TransformerPipeline } from "../transformation/transformer-pipeline";
|
||||
export { default as traverse } from "../traversal";
|
||||
export { default as buildExternalHelpers } from "../tools/build-external-helpers";
|
||||
export { version } from "../../../package";
|
||||
@@ -63,7 +65,7 @@ export function parse(code, opts = {}) {
|
||||
};
|
||||
opts.features = {};
|
||||
|
||||
for (var key in transform.transformers) {
|
||||
for (var key in transform.pipeline.transformers) {
|
||||
opts.features[key] = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ class CodeGenerator {
|
||||
retainLines: opts.retainLines,
|
||||
comments: opts.comments == null || opts.comments,
|
||||
compact: opts.compact,
|
||||
quotes: CodeGenerator.findCommonStringDelimeter(code, tokens),
|
||||
quotes: CodeGenerator.findCommonStringDelimiter(code, tokens),
|
||||
indent: {
|
||||
adjustMultilineComment: true,
|
||||
style: style,
|
||||
@@ -56,7 +56,7 @@ class CodeGenerator {
|
||||
return format;
|
||||
}
|
||||
|
||||
static findCommonStringDelimeter(code, tokens) {
|
||||
static findCommonStringDelimiter(code, tokens) {
|
||||
var occurences = {
|
||||
single: 0,
|
||||
double: 0
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import convertSourceMap from "convert-source-map";
|
||||
import * as optionParsers from "./option-parsers";
|
||||
import moduleFormatters from "../modules";
|
||||
import PluginManager from "./plugin-manager";
|
||||
import shebangRegex from "shebang-regex";
|
||||
import TraversalPath from "../../traversal/path";
|
||||
@@ -38,7 +39,7 @@ function checkPath(stack, path) {
|
||||
}
|
||||
|
||||
export default class File {
|
||||
constructor(opts = {}) {
|
||||
constructor(opts = {}, pipeline) {
|
||||
this.dynamicImportTypes = {};
|
||||
this.dynamicImportIds = {};
|
||||
this.dynamicImports = [];
|
||||
@@ -49,9 +50,10 @@ export default class File {
|
||||
this.data = {};
|
||||
this.uids = {};
|
||||
|
||||
this.log = new Logger(this, opts.filename || "unknown");
|
||||
this.opts = this.normalizeOptions(opts);
|
||||
this.ast = {};
|
||||
this.pipeline = pipeline;
|
||||
this.log = new Logger(this, opts.filename || "unknown");
|
||||
this.opts = this.normalizeOptions(opts);
|
||||
this.ast = {};
|
||||
|
||||
this.buildTransformers();
|
||||
}
|
||||
@@ -133,7 +135,7 @@ export default class File {
|
||||
}
|
||||
|
||||
var optionParser = optionParsers[option.type];
|
||||
if (optionParser) val = optionParser(key, val);
|
||||
if (optionParser) val = optionParser(key, val, this.pipeline);
|
||||
|
||||
if (option.alias) {
|
||||
opts[option.alias] = opts[option.alias] || val;
|
||||
@@ -200,7 +202,7 @@ export default class File {
|
||||
var stack = [];
|
||||
|
||||
// build internal transformers
|
||||
each(transform.transformers, function (transformer, key) {
|
||||
each(this.pipeline.transformers, function (transformer, key) {
|
||||
var pass = transformers[key] = transformer.buildPass(file);
|
||||
|
||||
if (pass.canTransform()) {
|
||||
@@ -235,7 +237,7 @@ export default class File {
|
||||
}
|
||||
|
||||
getModuleFormatter(type: string) {
|
||||
var ModuleFormatter = isFunction(type) ? type : transform.moduleFormatters[type];
|
||||
var ModuleFormatter = isFunction(type) ? type : moduleFormatters[type];
|
||||
|
||||
if (!ModuleFormatter) {
|
||||
var loc = util.resolveRelative(type);
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
import transform from "./../index";
|
||||
import * as util from "../../util";
|
||||
|
||||
export function transformerList(key, val) {
|
||||
export function transformerList(key, val, pipeline) {
|
||||
val = util.arrayify(val);
|
||||
|
||||
if (val.indexOf("all") >= 0 || val.indexOf(true) >= 0) {
|
||||
val = Object.keys(transform.transformers);
|
||||
val = Object.keys(pipeline.transformers);
|
||||
}
|
||||
|
||||
return transform._ensureTransformerNames(key, val);
|
||||
return pipeline._ensureTransformerNames(key, val);
|
||||
}
|
||||
|
||||
export function number(key, val) {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import * as node from "../../api/node";
|
||||
import * as messages from "../../messages";
|
||||
import * as util from "../../util";
|
||||
|
||||
|
||||
@@ -1,68 +1,34 @@
|
||||
import normalizeAst from "../helpers/normalize-ast";
|
||||
import Transformer from "./transformer";
|
||||
import object from "../helpers/object";
|
||||
import File from "./file";
|
||||
import each from "lodash/collection/each";
|
||||
import Pipeline from "./transformer-pipeline";
|
||||
|
||||
export default function transform(code: string, opts?: Object) {
|
||||
var file = new File(opts);
|
||||
return file.parse(code);
|
||||
}
|
||||
var pipeline = new Pipeline;
|
||||
|
||||
transform.fromAst = function (ast, code, opts) {
|
||||
ast = normalizeAst(ast);
|
||||
//
|
||||
|
||||
var file = new File(opts);
|
||||
file.addCode(code);
|
||||
file.transform(ast);
|
||||
return file.generate();
|
||||
};
|
||||
import transformers from "./transformers";
|
||||
pipeline.addTransformers(transformers);
|
||||
|
||||
transform._ensureTransformerNames = function (type: string, rawKeys: Array<string>) {
|
||||
var keys = [];
|
||||
//
|
||||
|
||||
for (var i = 0; i < rawKeys.length; i++) {
|
||||
var key = rawKeys[i];
|
||||
import deprecated from "./transformers/deprecated";
|
||||
pipeline.addDeprecated(deprecated);
|
||||
|
||||
var deprecatedKey = transform.deprecatedTransformerMap[key];
|
||||
var aliasKey = transform.aliasTransformerMap[key];
|
||||
if (aliasKey) {
|
||||
keys.push(aliasKey);
|
||||
} else if (deprecatedKey) {
|
||||
// deprecated key, remap it to the new one
|
||||
console.error(`The transformer ${key} has been renamed to ${deprecatedKey}`);
|
||||
rawKeys.push(deprecatedKey);
|
||||
} else if (transform.transformers[key]) {
|
||||
// valid key
|
||||
keys.push(key);
|
||||
} else if (transform.namespaces[key]) {
|
||||
// namespace, append all transformers within this namespace
|
||||
keys = keys.concat(transform.namespaces[key]);
|
||||
} else {
|
||||
// invalid key
|
||||
throw new ReferenceError(`Unknown transformer ${key} specified in ${type}`);
|
||||
}
|
||||
}
|
||||
//
|
||||
|
||||
return keys;
|
||||
};
|
||||
import aliases from "./transformers/aliases";
|
||||
pipeline.addAliases(aliases);
|
||||
|
||||
transform.transformerNamespaces = object();
|
||||
transform.transformers = object();
|
||||
transform.namespaces = object();
|
||||
//
|
||||
|
||||
transform.deprecatedTransformerMap = require("./transformers/deprecated");
|
||||
transform.aliasTransformerMap = require("./transformers/aliases");
|
||||
transform.moduleFormatters = require("./modules");
|
||||
import * as filters from "./transformers/filters";
|
||||
pipeline.addFilter(filters.internal);
|
||||
pipeline.addFilter(filters.blacklist);
|
||||
pipeline.addFilter(filters.whitelist);
|
||||
pipeline.addFilter(filters.stage);
|
||||
pipeline.addFilter(filters.optional);
|
||||
|
||||
import rawTransformers from "./transformers";
|
||||
//
|
||||
|
||||
each(rawTransformers, function (transformer, key) {
|
||||
var namespace = key.split(".")[0];
|
||||
|
||||
transform.namespaces[namespace] = transform.namespaces[namespace] || [];
|
||||
transform.namespaces[namespace].push(key);
|
||||
transform.transformerNamespaces[key] = namespace;
|
||||
|
||||
transform.transformers[key] = new Transformer(key, transformer);
|
||||
});
|
||||
var transform = pipeline.transform.bind(pipeline);
|
||||
transform.fromAst = pipeline.transformFromAst.bind(pipeline);
|
||||
transform.pipeline = pipeline;
|
||||
export default transform;
|
||||
|
||||
@@ -17,30 +17,7 @@ export default class TransformerPass {
|
||||
}
|
||||
|
||||
canTransform(): boolean {
|
||||
var transformer = this.transformer;
|
||||
|
||||
var opts = this.file.opts;
|
||||
var key = transformer.key;
|
||||
|
||||
// internal
|
||||
if (key[0] === "_") return true;
|
||||
|
||||
// blacklist
|
||||
var blacklist = opts.blacklist;
|
||||
if (blacklist.length && includes(blacklist, key)) return false;
|
||||
|
||||
// whitelist
|
||||
var whitelist = opts.whitelist;
|
||||
if (whitelist) return includes(whitelist, key);
|
||||
|
||||
// stage
|
||||
var stage = transformer.metadata.stage;
|
||||
if (stage != null && stage >= opts.stage) return true;
|
||||
|
||||
// optional
|
||||
if (transformer.metadata.optional && !includes(opts.optional, key)) return false;
|
||||
|
||||
return true;
|
||||
return this.file.pipeline.canTransform(this.transformer, this.file.opts);
|
||||
}
|
||||
|
||||
checkPath(path: TraversalPath): boolean {
|
||||
|
||||
100
src/babel/transformation/transformer-pipeline.js
Normal file
100
src/babel/transformation/transformer-pipeline.js
Normal file
@@ -0,0 +1,100 @@
|
||||
import Transformer from "./transformer";
|
||||
import normalizeAst from "../helpers/normalize-ast";
|
||||
import assign from "lodash/object/assign";
|
||||
import object from "../helpers/object";
|
||||
import File from "./file";
|
||||
|
||||
export default class TransformerPipeline {
|
||||
constructor() {
|
||||
this.transformers = object();
|
||||
this.namespaces = object();
|
||||
this.deprecated = object();
|
||||
this.aliases = object();
|
||||
this.filters = [];
|
||||
}
|
||||
|
||||
addTransformers(transformers) {
|
||||
for (var key in transformers) {
|
||||
this.addTransformer(key, transformers[key]);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
addTransformer(key, transformer) {
|
||||
if (this.transformers[key]) throw new Error(); // todo: error
|
||||
|
||||
var namespace = key.split(".")[0];
|
||||
this.namespaces[namespace] = this.namespaces[namespace] || [];
|
||||
this.namespaces[namespace].push(key);
|
||||
this.namespaces[key] = namespace;
|
||||
|
||||
this.transformers[key] = new Transformer(key, transformer);
|
||||
}
|
||||
|
||||
addAliases(names) {
|
||||
assign(this.aliases, names);
|
||||
return this;
|
||||
}
|
||||
|
||||
addDeprecated(names) {
|
||||
assign(this.deprecated, names);
|
||||
return this;
|
||||
}
|
||||
|
||||
addFilter(filter: Function) {
|
||||
this.filters.push(filter);
|
||||
return this;
|
||||
}
|
||||
|
||||
canTransform(transformer, fileOpts) {
|
||||
for (var filter of (this.filters: Array)) {
|
||||
var result = filter(transformer, fileOpts);
|
||||
if (result != null) return result;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
transform(code: string, opts?: Object) {
|
||||
var file = new File(opts, this);
|
||||
return file.parse(code);
|
||||
}
|
||||
|
||||
transformFromAst(ast, code, opts) {
|
||||
ast = normalizeAst(ast);
|
||||
|
||||
var file = new File(opts, this);
|
||||
file.addCode(code);
|
||||
file.transform(ast);
|
||||
return file.generate();
|
||||
}
|
||||
|
||||
_ensureTransformerNames(type: string, rawKeys: Array<string>) {
|
||||
var keys = [];
|
||||
|
||||
for (var i = 0; i < rawKeys.length; i++) {
|
||||
var key = rawKeys[i];
|
||||
|
||||
var deprecatedKey = this.deprecated[key];
|
||||
var aliasKey = this.aliases[key];
|
||||
if (aliasKey) {
|
||||
keys.push(aliasKey);
|
||||
} else if (deprecatedKey) {
|
||||
// deprecated key, remap it to the new one
|
||||
console.error(`[BABEL] The transformer ${key} has been renamed to ${deprecatedKey}`);
|
||||
rawKeys.push(deprecatedKey);
|
||||
} else if (this.transformers[key]) {
|
||||
// valid key
|
||||
keys.push(key);
|
||||
} else if (this.namespaces[key]) {
|
||||
// namespace, append all transformers within this namespace
|
||||
keys = keys.concat(this.namespaces[key]);
|
||||
} else {
|
||||
// invalid key
|
||||
throw new ReferenceError(`Unknown transformer ${key} specified in ${type}`);
|
||||
}
|
||||
}
|
||||
|
||||
return keys;
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@ import each from "lodash/collection/each";
|
||||
*/
|
||||
|
||||
export default class Transformer {
|
||||
constructor(transformerKey: string, transformer: Object, opts: Object) {
|
||||
constructor(transformerKey: string, transformer: Object) {
|
||||
transformer = assign({}, transformer);
|
||||
|
||||
var take = function (key) {
|
||||
@@ -40,7 +40,6 @@ export default class Transformer {
|
||||
//
|
||||
|
||||
this.handlers = this.normalize(transformer);
|
||||
this.opts = this.opts || {};
|
||||
this.key = transformerKey;
|
||||
|
||||
//
|
||||
|
||||
24
src/babel/transformation/transformers/filters.js
Normal file
24
src/babel/transformation/transformers/filters.js
Normal file
@@ -0,0 +1,24 @@
|
||||
import includes from "lodash/collection/includes";
|
||||
|
||||
export function internal(transformer, opts) {
|
||||
if (transformer.key[0] === "_") return true;
|
||||
}
|
||||
|
||||
export function blacklist(transformer, opts) {
|
||||
var blacklist = opts.blacklist;
|
||||
if (blacklist.length && includes(blacklist, transformer.key)) return false;
|
||||
}
|
||||
|
||||
export function whitelist(transformer, opts) {
|
||||
var whitelist = opts.whitelist;
|
||||
if (whitelist) return includes(whitelist, transformer.key);
|
||||
}
|
||||
|
||||
export function stage(transformer, opts) {
|
||||
var stage = transformer.metadata.stage;
|
||||
if (stage != null && stage >= opts.stage) return true;
|
||||
}
|
||||
|
||||
export function optional(transformer, opts) {
|
||||
if (transformer.metadata.optional && !includes(opts.optional, transformer.key)) return false;
|
||||
}
|
||||
@@ -21,6 +21,38 @@ export var metadata = {
|
||||
optional: true
|
||||
};
|
||||
|
||||
export function Identifier(node, parent, scope) {
|
||||
if (!this.isReferenced()) return;
|
||||
|
||||
var binding = scope.getBinding(node.name);
|
||||
if (!binding || binding.references > 1 || !binding.constant) return;
|
||||
|
||||
var replacement = binding.path.node;
|
||||
if (t.isVariableDeclarator(replacement)) {
|
||||
replacement = replacement.init;
|
||||
}
|
||||
t.toExpression(replacement);
|
||||
|
||||
scope.removeBinding(node.name);
|
||||
|
||||
binding.path.remove();
|
||||
return replacement;
|
||||
}
|
||||
|
||||
export function FunctionDeclaration(node, parent, scope) {
|
||||
var bindingInfo = scope.getBinding(node.id.name);
|
||||
if (bindingInfo && !bindingInfo.referenced) {
|
||||
this.remove();
|
||||
}
|
||||
}
|
||||
|
||||
export { FunctionDeclaration as ClassDeclaration };
|
||||
|
||||
export function VariableDeclarator(node, parent, scope) {
|
||||
if (!t.isIdentifier(node.id) || !scope.isPure(node.init)) return;
|
||||
FunctionDeclaration.apply(this, arguments);
|
||||
}
|
||||
|
||||
export function ConditionalExpression(node, parent, scope) {
|
||||
var evaluateTest = this.get("test").evaluateTruthy();
|
||||
if (evaluateTest === true) {
|
||||
|
||||
@@ -3,6 +3,8 @@ import * as t from "../types";
|
||||
export default class Binding {
|
||||
constructor({ identifier, scope, path, kind }) {
|
||||
this.identifier = identifier;
|
||||
this.references = 0;
|
||||
this.referenced = false;
|
||||
this.constant = true;
|
||||
this.scope = scope;
|
||||
this.path = path;
|
||||
@@ -58,6 +60,15 @@ export default class Binding {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
*/
|
||||
|
||||
reference() {
|
||||
this.referenced = true;
|
||||
this.references++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
*/
|
||||
|
||||
@@ -319,6 +319,12 @@ export default class TraversalPath {
|
||||
var parent = this.parent;
|
||||
if (!parentPath) return;
|
||||
|
||||
// we've just removed the last declarator of a variable declaration so there's no point in
|
||||
// keeping it
|
||||
if (parentPath.isVariableDeclaration() && parent.declarations.length === 0) {
|
||||
return parentPath.remove();
|
||||
}
|
||||
|
||||
// we're the child of an expression statement so we should remove the parent
|
||||
if (parentPath.isExpressionStatement()) {
|
||||
return parentPath.remove();
|
||||
@@ -650,6 +656,10 @@ export default class TraversalPath {
|
||||
return this.shouldStop;
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
*/
|
||||
|
||||
getSibling(key) {
|
||||
return TraversalPath.get(this.parentPath, null, this.parent, this.container, key, this.file);
|
||||
}
|
||||
|
||||
@@ -40,8 +40,13 @@ var functionVariableVisitor = {
|
||||
|
||||
var programReferenceVisitor = {
|
||||
enter(node, parent, scope, state) {
|
||||
if (t.isReferencedIdentifier(node, parent) && !scope.hasBinding(node.name)) {
|
||||
state.addGlobal(node);
|
||||
if (t.isReferencedIdentifier(node, parent)) {
|
||||
var bindingInfo = scope.getBinding(node.name);
|
||||
if (bindingInfo) {
|
||||
bindingInfo.reference();
|
||||
} else {
|
||||
state.addGlobal(node);
|
||||
}
|
||||
} else if (t.isLabeledStatement(node)) {
|
||||
state.addGlobal(node);
|
||||
} else if (t.isAssignmentExpression(node)) {
|
||||
@@ -482,6 +487,19 @@ export default class Scope {
|
||||
this.crawl();
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
*/
|
||||
|
||||
isPure(node) {
|
||||
if (t.isIdentifier(node)) {
|
||||
var bindingInfo = this.getBinding(node.name);
|
||||
return bindingInfo.constant;
|
||||
} else {
|
||||
return t.isPure(node);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
*/
|
||||
|
||||
@@ -26,9 +26,9 @@
|
||||
"ExportNamedDeclaration": ["Statement", "Declaration", "ModuleDeclaration", "ExportDeclaration"],
|
||||
"ImportDeclaration": ["Statement", "Declaration", "ModuleDeclaration"],
|
||||
|
||||
"ArrowFunctionExpression": ["Scopable", "Function", "Expression"],
|
||||
"FunctionDeclaration": ["Scopable", "Function", "Statement", "Declaration"],
|
||||
"FunctionExpression": ["Scopable", "Function", "Expression"],
|
||||
"ArrowFunctionExpression": ["Scopable", "Function", "Expression", "Pure"],
|
||||
"FunctionDeclaration": ["Scopable", "Function", "Statement", "Pure", "Declaration"],
|
||||
"FunctionExpression": ["Scopable", "Function", "Expression", "Pure"],
|
||||
|
||||
"BlockStatement": ["Scopable", "Statement"],
|
||||
"Program": ["Scopable"],
|
||||
@@ -41,8 +41,8 @@
|
||||
"SpreadProperty": ["UnaryLike"],
|
||||
"SpreadElement": ["UnaryLike"],
|
||||
|
||||
"ClassDeclaration": ["Scopable", "Class", "Statement", "Declaration"],
|
||||
"ClassExpression": ["Scopable", "Class", "Expression"],
|
||||
"ClassDeclaration": ["Scopable", "Class", "Pure", "Statement", "Declaration"],
|
||||
"ClassExpression": ["Scopable", "Class", "Pure", "Expression"],
|
||||
|
||||
"ForOfStatement": ["Scopable", "Statement", "For", "Loop"],
|
||||
"ForInStatement": ["Scopable", "Statement", "For", "Loop"],
|
||||
@@ -62,7 +62,7 @@
|
||||
"ConditionalExpression": ["Expression"],
|
||||
"DoExpression": ["Expression"],
|
||||
"Identifier": ["Expression"],
|
||||
"Literal": ["Expression"],
|
||||
"Literal": ["Expression", "Pure"],
|
||||
"MemberExpression": ["Expression"],
|
||||
"MetaProperty": ["Expression"],
|
||||
"NewExpression": ["Expression"],
|
||||
@@ -80,15 +80,15 @@
|
||||
"ArrayTypeAnnotation": ["Flow"],
|
||||
"BooleanTypeAnnotation": ["Flow"],
|
||||
"ClassImplements": ["Flow"],
|
||||
"DeclareClass": ["Flow"],
|
||||
"DeclareFunction": ["Flow"],
|
||||
"DeclareModule": ["Flow"],
|
||||
"DeclareVariable": ["Flow"],
|
||||
"DeclareClass": ["Flow", "Statement"],
|
||||
"DeclareFunction": ["Flow", "Statement"],
|
||||
"DeclareModule": ["Flow", "Statement"],
|
||||
"DeclareVariable": ["Flow", "Statement"],
|
||||
"FunctionTypeAnnotation": ["Flow"],
|
||||
"FunctionTypeParam": ["Flow"],
|
||||
"GenericTypeAnnotation": ["Flow"],
|
||||
"InterfaceExtends": ["Flow"],
|
||||
"InterfaceDeclaration": ["Flow"],
|
||||
"InterfaceDeclaration": ["Flow", "Statement", "Declaration"],
|
||||
"IntersectionTypeAnnotation": ["Flow"],
|
||||
"NullableTypeAnnotation": ["Flow"],
|
||||
"NumberTypeAnnotation": ["Flow"],
|
||||
@@ -96,7 +96,7 @@
|
||||
"StringTypeAnnotation": ["Flow"],
|
||||
"TupleTypeAnnotation": ["Flow"],
|
||||
"TypeofTypeAnnotation": ["Flow"],
|
||||
"TypeAlias": ["Flow"],
|
||||
"TypeAlias": ["Flow", "Statement"],
|
||||
"TypeAnnotation": ["Flow"],
|
||||
"TypeCastExpression": ["Flow"],
|
||||
"TypeParameterDeclaration": ["Flow"],
|
||||
|
||||
@@ -88,7 +88,7 @@ export function arrayify(val: any, mapFn?: Function): Array {
|
||||
return val;
|
||||
}
|
||||
|
||||
throw new TypeError("illegal type for arrayify");
|
||||
return [val];
|
||||
}
|
||||
|
||||
export function booleanify(val: any): boolean {
|
||||
|
||||
@@ -19,7 +19,7 @@ suite("api", function () {
|
||||
});
|
||||
|
||||
test("addHelper unknown", function () {
|
||||
var file = new File;
|
||||
var file = new File({}, transform.pipeline);
|
||||
assert.throws(function () {
|
||||
file.addHelper("foob");
|
||||
}, /Unknown helper foob/);
|
||||
@@ -40,11 +40,11 @@ suite("api", function () {
|
||||
});
|
||||
|
||||
test("extra options", function () {
|
||||
var file1 = new File({ extra: { foo: "bar" } });
|
||||
var file1 = new File({ extra: { foo: "bar" } }, transform.pipeline);
|
||||
assert.equal(file1.opts.extra.foo, "bar");
|
||||
|
||||
var file2 = new File;
|
||||
var file3 = new File;
|
||||
var file2 = new File({}, transform.pipeline);
|
||||
var file3 = new File({}, transform.pipeline);
|
||||
assert.ok(file2.opts.extra !== file3.opts.extra);
|
||||
});
|
||||
|
||||
|
||||
3
test/core/fixtures/bundler/basic/simple-import/actual.js
Normal file
3
test/core/fixtures/bundler/basic/simple-import/actual.js
Normal file
@@ -0,0 +1,3 @@
|
||||
import foo from "./fixtures/foo";
|
||||
|
||||
foo();
|
||||
@@ -0,0 +1,7 @@
|
||||
"use strict";
|
||||
|
||||
function fixtures$foo() {
|
||||
return "foobar";
|
||||
}
|
||||
|
||||
fixtures$foo();
|
||||
@@ -0,0 +1,3 @@
|
||||
export default function () {
|
||||
return "foobar";
|
||||
}
|
||||
@@ -72,10 +72,7 @@ suite("util", function () {
|
||||
assert.deepEqual(util.arrayify("foo"), ["foo"]);
|
||||
assert.deepEqual(util.arrayify("foo,bar"), ["foo", "bar"]);
|
||||
assert.deepEqual(util.arrayify(["foo", "bar"]), ["foo", "bar"]);
|
||||
|
||||
assert.throws(function () {
|
||||
util.arrayify({});
|
||||
}, /illegal type for arrayify/);
|
||||
assert.deepEqual(util.arrayify({ foo: "bar" }), [{ foo: "bar" }]);
|
||||
});
|
||||
|
||||
test("regexify", function () {
|
||||
|
||||
Reference in New Issue
Block a user