Compare commits
77 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
86c6d4e769 | ||
|
|
bf2d527cfe | ||
|
|
6b59ea8eac | ||
|
|
72e3cb9243 | ||
|
|
5e5ede6058 | ||
|
|
d25944ea1f | ||
|
|
fce2aa8fa3 | ||
|
|
0112c63779 | ||
|
|
6a4e93bf0f | ||
|
|
4328e920d2 | ||
|
|
bbbf0a895d | ||
|
|
3289b33806 | ||
|
|
f4b9faa6b3 | ||
|
|
239b77816f | ||
|
|
8565e2b4e5 | ||
|
|
4317a46a3e | ||
|
|
81ca29adc3 | ||
|
|
c1a6ff7f44 | ||
|
|
7e6e5d4746 | ||
|
|
12d650e195 | ||
|
|
8fb58492df | ||
|
|
2c0c2f12df | ||
|
|
01e5354fd9 | ||
|
|
0b100c4273 | ||
|
|
340e75eb59 | ||
|
|
53808a6d45 | ||
|
|
e6326332b6 | ||
|
|
9e0cf84505 | ||
|
|
b7eea7b08c | ||
|
|
92dd67856e | ||
|
|
a2bb587e24 | ||
|
|
0c570cb599 | ||
|
|
db6fab2c8f | ||
|
|
d92deb52b6 | ||
|
|
b8b70f2f4a | ||
|
|
a8a3f6d34d | ||
|
|
9847d226e1 | ||
|
|
3d48a16305 | ||
|
|
3d24cc9ae5 | ||
|
|
5acc58dd68 | ||
|
|
34f02f06a6 | ||
|
|
6d3fe5b85c | ||
|
|
3878bd812c | ||
|
|
0717eaddce | ||
|
|
102cbbe493 | ||
|
|
d981b30194 | ||
|
|
0fc02f2cf0 | ||
|
|
f24b5164d4 | ||
|
|
4be27ee72c | ||
|
|
f0070e4828 | ||
|
|
ce8beec22c | ||
|
|
b30bdf2294 | ||
|
|
63b44a3e6e | ||
|
|
74aaf848ed | ||
|
|
95de5400e6 | ||
|
|
fe7079802b | ||
|
|
61ddb14e25 | ||
|
|
ca7a93cd64 | ||
|
|
90a1c81d30 | ||
|
|
5e9089d104 | ||
|
|
1a716943bc | ||
|
|
c28415c38a | ||
|
|
e1491de6b8 | ||
|
|
253ea8cd18 | ||
|
|
d37bad3149 | ||
|
|
a2b912bc77 | ||
|
|
f1bfbe44e2 | ||
|
|
dbdd07d0b8 | ||
|
|
166909998e | ||
|
|
a8ec4c965c | ||
|
|
d2aff67c6c | ||
|
|
3353de225d | ||
|
|
203ebeef20 | ||
|
|
032cf990c3 | ||
|
|
16cdb43c67 | ||
|
|
6f622033c5 | ||
|
|
1f2f4ce4f3 |
65
CHANGELOG.md
65
CHANGELOG.md
@@ -13,6 +13,71 @@ _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.13
|
||||
|
||||
* **Bug Fix**
|
||||
* Fix `ExportDeclaration`s being incorrectly removed when using the `utility.deadCodeElimination` transformer.
|
||||
* Fix position of `utility` transformers.
|
||||
* **New Feature**
|
||||
* Add built-in `esquery` support.
|
||||
* **Internal**
|
||||
* Consolidate notion of "virtual types".
|
||||
|
||||
## 5.2.12
|
||||
|
||||
* **Polish**
|
||||
* Make UID generation based on module declarations **much** nicer.
|
||||
* **Internal**
|
||||
* Remove internal check for traversal path replacement of self. This is a pattern that **could** come up in the wild and it could lead to pretty nasty code and may lead to internal regressions as the test coverage isn't 100% :( Instead, just put it in the fast path.
|
||||
|
||||
## 5.2.11
|
||||
|
||||
* **Internal**
|
||||
* Rename `getModuleName` option to `getModuleId`, doh.
|
||||
|
||||
## 5.2.10
|
||||
|
||||
* **Bug Fix**
|
||||
* Fix numerous issues in `replaceWithSourceString`. Thanks [@pangratz](https://github.com/pangratz)!
|
||||
* **New Feature**
|
||||
* Add `getModuleName` option. Thanks [@jayphelps](https://github.com/jayphelps)!
|
||||
|
||||
## 5.2.9
|
||||
|
||||
* **Bug Fix**
|
||||
* Fix `_blockHoist` transformer incorrectly sorting nodes on shitty environments that aren't spec compliant in their key order.
|
||||
* Fix broken `parse` API method reference to an undeclared import.
|
||||
|
||||
## 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
|
||||
|
||||
* **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**
|
||||
|
||||
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
|
||||
UGLIFY_CMD = node_modules/uglify-js/bin/uglifyjs
|
||||
#UGLIFY_CMD = node_modules/uglify-js/bin/uglifyjs --mangle sort
|
||||
JSHINT_CMD = node_modules/jshint/bin/jshint
|
||||
MOCHA_CMD = node_modules/mocha/bin/_mocha
|
||||
BABEL_CMD = node_modules/babel/bin/babel
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "babel-core",
|
||||
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
|
||||
"version": "5.2.3",
|
||||
"version": "5.2.13",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://babeljs.io/",
|
||||
"repository": "babel/babel",
|
||||
@@ -27,6 +27,7 @@
|
||||
"test": "make test"
|
||||
},
|
||||
"dependencies": {
|
||||
"acorn-jsx": "^1.0.0",
|
||||
"ast-types": "~0.7.0",
|
||||
"bluebird": "^2.9.25",
|
||||
"chalk": "^1.0.0",
|
||||
@@ -34,7 +35,8 @@
|
||||
"core-js": "^0.9.0",
|
||||
"debug": "^2.1.1",
|
||||
"detect-indent": "^3.0.0",
|
||||
"estraverse": "^3.0.0",
|
||||
"esquery": "^0.4.0",
|
||||
"estraverse": "^4.0.0",
|
||||
"esutils": "^2.0.0",
|
||||
"fs-readdir-recursive": "^0.1.0",
|
||||
"globals": "^6.4.0",
|
||||
|
||||
@@ -30,7 +30,7 @@ module.exports = function (commander, filenames, opts) {
|
||||
var handleFile = function (src, filename) {
|
||||
if (util.shouldIgnore(src)) return;
|
||||
|
||||
if (util.canCompile(filename)) {
|
||||
if (util.canCompile(filename, commander.extensions)) {
|
||||
write(src, filename);
|
||||
} else if (commander.copyFiles) {
|
||||
outputFileSync(path.join(commander.outDir, filename), fs.readFileSync(src));
|
||||
|
||||
@@ -27,9 +27,14 @@ module.exports = function (commander, filenames, opts) {
|
||||
|
||||
if (result.map) {
|
||||
var consumer = new sourceMap.SourceMapConsumer(result.map);
|
||||
var sourceFilename = filename;
|
||||
|
||||
map._sources.add(filename);
|
||||
map.setSourceContent(filename, result.actual);
|
||||
if (commander.outFile) {
|
||||
sourceFilename = path.relative(path.dirname(commander.outFile), sourceFilename);
|
||||
}
|
||||
|
||||
map._sources.add(sourceFilename);
|
||||
map.setSourceContent(sourceFilename, result.actual);
|
||||
|
||||
consumer.eachMapping(function (mapping) {
|
||||
map._mappings.add({
|
||||
@@ -37,7 +42,7 @@ module.exports = function (commander, filenames, opts) {
|
||||
generatedColumn: mapping.generatedColumn,
|
||||
originalLine: mapping.originalLine,
|
||||
originalColumn: mapping.originalColumn,
|
||||
source: filename
|
||||
source: sourceFilename
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var commander = require("commander");
|
||||
var transform = require("babel-core").transform;
|
||||
var kebabCase = require("lodash/string/kebabCase");
|
||||
var options = require("babel-core").options;
|
||||
var util = require("babel-core").util;
|
||||
var each = require("lodash/collection/each");
|
||||
var keys = require("lodash/object/keys");
|
||||
var fs = require("fs");
|
||||
var glob = require("glob");
|
||||
var moduleFormatters = require("babel-core/lib/babel/transformation/modules");
|
||||
var commander = require("commander");
|
||||
var transform = require("babel-core").transform;
|
||||
var kebabCase = require("lodash/string/kebabCase");
|
||||
var options = require("babel-core").options;
|
||||
var util = require("babel-core").util;
|
||||
var each = require("lodash/collection/each");
|
||||
var keys = require("lodash/object/keys");
|
||||
var fs = require("fs");
|
||||
var glob = require("glob");
|
||||
|
||||
each(options, function (option, key) {
|
||||
if (option.hidden) return;
|
||||
@@ -36,6 +37,7 @@ each(options, function (option, key) {
|
||||
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("-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");
|
||||
@@ -57,8 +59,8 @@ commander.on("--help", function () {
|
||||
console.log();
|
||||
};
|
||||
|
||||
outKeys("Transformers", transform.transformers);
|
||||
outKeys("Module formatters", transform.moduleFormatters);
|
||||
outKeys("Transformers", transform.pipeline.transformers);
|
||||
outKeys("Module formatters", moduleFormatters);
|
||||
});
|
||||
|
||||
var pkg = require("../../package.json");
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
{
|
||||
"name": "babel",
|
||||
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
|
||||
"version": "5.2.2",
|
||||
"version": "5.2.12",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://babeljs.io/",
|
||||
"repository": "babel/babel",
|
||||
"preferGlobal": true,
|
||||
"dependencies": {
|
||||
"babel-core": "^5.2.2",
|
||||
"babel-core": "^5.2.12",
|
||||
"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.2",
|
||||
"version": "5.2.12",
|
||||
"repository": "babel/babel",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"dependencies": {
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
export * from "./src/index";
|
||||
import "./plugins/flow";
|
||||
import "./plugins/jsx";
|
||||
|
||||
import inject from "acorn-jsx/inject";
|
||||
import * as acorn from "./src/index";
|
||||
inject(acorn);
|
||||
|
||||
@@ -1,658 +0,0 @@
|
||||
var acorn = require("../src/index")
|
||||
|
||||
var tt = acorn.tokTypes;
|
||||
var tc = acorn.tokContexts;
|
||||
|
||||
tc.j_oTag = new acorn.TokContext("<tag", false);
|
||||
tc.j_cTag = new acorn.TokContext("</tag", false);
|
||||
tc.j_expr = new acorn.TokContext("<tag>...</tag>", true, true);
|
||||
|
||||
tt.jsxName = new acorn.TokenType("jsxName");
|
||||
tt.jsxText = new acorn.TokenType("jsxText", {beforeExpr: true});
|
||||
tt.jsxTagStart = new acorn.TokenType("jsxTagStart");
|
||||
tt.jsxTagEnd = new acorn.TokenType("jsxTagEnd");
|
||||
|
||||
tt.jsxTagStart.updateContext = function() {
|
||||
this.context.push(tc.j_expr); // treat as beginning of JSX expression
|
||||
this.context.push(tc.j_oTag); // start opening tag context
|
||||
this.exprAllowed = false;
|
||||
};
|
||||
tt.jsxTagEnd.updateContext = function(prevType) {
|
||||
var out = this.context.pop();
|
||||
if (out === tc.j_oTag && prevType === tt.slash || out === tc.j_cTag) {
|
||||
this.context.pop();
|
||||
this.exprAllowed = this.curContext() === tc.j_expr;
|
||||
} else {
|
||||
this.exprAllowed = true;
|
||||
}
|
||||
};
|
||||
|
||||
var pp = acorn.Parser.prototype;
|
||||
|
||||
// Reads inline JSX contents token.
|
||||
|
||||
pp.jsx_readToken = function() {
|
||||
var out = "", chunkStart = this.pos;
|
||||
for (;;) {
|
||||
if (this.pos >= this.input.length)
|
||||
this.raise(this.start, "Unterminated JSX contents");
|
||||
var ch = this.input.charCodeAt(this.pos);
|
||||
|
||||
switch (ch) {
|
||||
case 60: // '<'
|
||||
case 123: // '{'
|
||||
if (this.pos === this.start) {
|
||||
if (ch === 60 && this.exprAllowed) {
|
||||
++this.pos;
|
||||
return this.finishToken(tt.jsxTagStart);
|
||||
}
|
||||
return this.getTokenFromCode(ch);
|
||||
}
|
||||
out += this.input.slice(chunkStart, this.pos);
|
||||
return this.finishToken(tt.jsxText, out);
|
||||
|
||||
case 38: // '&'
|
||||
out += this.input.slice(chunkStart, this.pos);
|
||||
out += this.jsx_readEntity();
|
||||
chunkStart = this.pos;
|
||||
break;
|
||||
|
||||
default:
|
||||
if (acorn.isNewLine(ch)) {
|
||||
out += this.input.slice(chunkStart, this.pos);
|
||||
++this.pos;
|
||||
if (ch === 13 && this.input.charCodeAt(this.pos) === 10) {
|
||||
++this.pos;
|
||||
out += "\n";
|
||||
} else {
|
||||
out += String.fromCharCode(ch);
|
||||
}
|
||||
if (this.options.locations) {
|
||||
++this.curLine;
|
||||
this.lineStart = this.pos;
|
||||
}
|
||||
chunkStart = this.pos;
|
||||
} else {
|
||||
++this.pos;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
pp.jsx_readString = function(quote) {
|
||||
var out = "", chunkStart = ++this.pos;
|
||||
for (;;) {
|
||||
if (this.pos >= this.input.length)
|
||||
this.raise(this.start, "Unterminated string constant");
|
||||
var ch = this.input.charCodeAt(this.pos);
|
||||
if (ch === quote) break;
|
||||
if (ch === 38) { // '&'
|
||||
out += this.input.slice(chunkStart, this.pos);
|
||||
out += this.jsx_readEntity();
|
||||
chunkStart = this.pos;
|
||||
} else {
|
||||
++this.pos;
|
||||
}
|
||||
}
|
||||
out += this.input.slice(chunkStart, this.pos++);
|
||||
return this.finishToken(tt.string, out);
|
||||
};
|
||||
|
||||
var XHTMLEntities = {
|
||||
quot: '\u0022',
|
||||
amp: '&',
|
||||
apos: '\u0027',
|
||||
lt: '<',
|
||||
gt: '>',
|
||||
nbsp: '\u00A0',
|
||||
iexcl: '\u00A1',
|
||||
cent: '\u00A2',
|
||||
pound: '\u00A3',
|
||||
curren: '\u00A4',
|
||||
yen: '\u00A5',
|
||||
brvbar: '\u00A6',
|
||||
sect: '\u00A7',
|
||||
uml: '\u00A8',
|
||||
copy: '\u00A9',
|
||||
ordf: '\u00AA',
|
||||
laquo: '\u00AB',
|
||||
not: '\u00AC',
|
||||
shy: '\u00AD',
|
||||
reg: '\u00AE',
|
||||
macr: '\u00AF',
|
||||
deg: '\u00B0',
|
||||
plusmn: '\u00B1',
|
||||
sup2: '\u00B2',
|
||||
sup3: '\u00B3',
|
||||
acute: '\u00B4',
|
||||
micro: '\u00B5',
|
||||
para: '\u00B6',
|
||||
middot: '\u00B7',
|
||||
cedil: '\u00B8',
|
||||
sup1: '\u00B9',
|
||||
ordm: '\u00BA',
|
||||
raquo: '\u00BB',
|
||||
frac14: '\u00BC',
|
||||
frac12: '\u00BD',
|
||||
frac34: '\u00BE',
|
||||
iquest: '\u00BF',
|
||||
Agrave: '\u00C0',
|
||||
Aacute: '\u00C1',
|
||||
Acirc: '\u00C2',
|
||||
Atilde: '\u00C3',
|
||||
Auml: '\u00C4',
|
||||
Aring: '\u00C5',
|
||||
AElig: '\u00C6',
|
||||
Ccedil: '\u00C7',
|
||||
Egrave: '\u00C8',
|
||||
Eacute: '\u00C9',
|
||||
Ecirc: '\u00CA',
|
||||
Euml: '\u00CB',
|
||||
Igrave: '\u00CC',
|
||||
Iacute: '\u00CD',
|
||||
Icirc: '\u00CE',
|
||||
Iuml: '\u00CF',
|
||||
ETH: '\u00D0',
|
||||
Ntilde: '\u00D1',
|
||||
Ograve: '\u00D2',
|
||||
Oacute: '\u00D3',
|
||||
Ocirc: '\u00D4',
|
||||
Otilde: '\u00D5',
|
||||
Ouml: '\u00D6',
|
||||
times: '\u00D7',
|
||||
Oslash: '\u00D8',
|
||||
Ugrave: '\u00D9',
|
||||
Uacute: '\u00DA',
|
||||
Ucirc: '\u00DB',
|
||||
Uuml: '\u00DC',
|
||||
Yacute: '\u00DD',
|
||||
THORN: '\u00DE',
|
||||
szlig: '\u00DF',
|
||||
agrave: '\u00E0',
|
||||
aacute: '\u00E1',
|
||||
acirc: '\u00E2',
|
||||
atilde: '\u00E3',
|
||||
auml: '\u00E4',
|
||||
aring: '\u00E5',
|
||||
aelig: '\u00E6',
|
||||
ccedil: '\u00E7',
|
||||
egrave: '\u00E8',
|
||||
eacute: '\u00E9',
|
||||
ecirc: '\u00EA',
|
||||
euml: '\u00EB',
|
||||
igrave: '\u00EC',
|
||||
iacute: '\u00ED',
|
||||
icirc: '\u00EE',
|
||||
iuml: '\u00EF',
|
||||
eth: '\u00F0',
|
||||
ntilde: '\u00F1',
|
||||
ograve: '\u00F2',
|
||||
oacute: '\u00F3',
|
||||
ocirc: '\u00F4',
|
||||
otilde: '\u00F5',
|
||||
ouml: '\u00F6',
|
||||
divide: '\u00F7',
|
||||
oslash: '\u00F8',
|
||||
ugrave: '\u00F9',
|
||||
uacute: '\u00FA',
|
||||
ucirc: '\u00FB',
|
||||
uuml: '\u00FC',
|
||||
yacute: '\u00FD',
|
||||
thorn: '\u00FE',
|
||||
yuml: '\u00FF',
|
||||
OElig: '\u0152',
|
||||
oelig: '\u0153',
|
||||
Scaron: '\u0160',
|
||||
scaron: '\u0161',
|
||||
Yuml: '\u0178',
|
||||
fnof: '\u0192',
|
||||
circ: '\u02C6',
|
||||
tilde: '\u02DC',
|
||||
Alpha: '\u0391',
|
||||
Beta: '\u0392',
|
||||
Gamma: '\u0393',
|
||||
Delta: '\u0394',
|
||||
Epsilon: '\u0395',
|
||||
Zeta: '\u0396',
|
||||
Eta: '\u0397',
|
||||
Theta: '\u0398',
|
||||
Iota: '\u0399',
|
||||
Kappa: '\u039A',
|
||||
Lambda: '\u039B',
|
||||
Mu: '\u039C',
|
||||
Nu: '\u039D',
|
||||
Xi: '\u039E',
|
||||
Omicron: '\u039F',
|
||||
Pi: '\u03A0',
|
||||
Rho: '\u03A1',
|
||||
Sigma: '\u03A3',
|
||||
Tau: '\u03A4',
|
||||
Upsilon: '\u03A5',
|
||||
Phi: '\u03A6',
|
||||
Chi: '\u03A7',
|
||||
Psi: '\u03A8',
|
||||
Omega: '\u03A9',
|
||||
alpha: '\u03B1',
|
||||
beta: '\u03B2',
|
||||
gamma: '\u03B3',
|
||||
delta: '\u03B4',
|
||||
epsilon: '\u03B5',
|
||||
zeta: '\u03B6',
|
||||
eta: '\u03B7',
|
||||
theta: '\u03B8',
|
||||
iota: '\u03B9',
|
||||
kappa: '\u03BA',
|
||||
lambda: '\u03BB',
|
||||
mu: '\u03BC',
|
||||
nu: '\u03BD',
|
||||
xi: '\u03BE',
|
||||
omicron: '\u03BF',
|
||||
pi: '\u03C0',
|
||||
rho: '\u03C1',
|
||||
sigmaf: '\u03C2',
|
||||
sigma: '\u03C3',
|
||||
tau: '\u03C4',
|
||||
upsilon: '\u03C5',
|
||||
phi: '\u03C6',
|
||||
chi: '\u03C7',
|
||||
psi: '\u03C8',
|
||||
omega: '\u03C9',
|
||||
thetasym: '\u03D1',
|
||||
upsih: '\u03D2',
|
||||
piv: '\u03D6',
|
||||
ensp: '\u2002',
|
||||
emsp: '\u2003',
|
||||
thinsp: '\u2009',
|
||||
zwnj: '\u200C',
|
||||
zwj: '\u200D',
|
||||
lrm: '\u200E',
|
||||
rlm: '\u200F',
|
||||
ndash: '\u2013',
|
||||
mdash: '\u2014',
|
||||
lsquo: '\u2018',
|
||||
rsquo: '\u2019',
|
||||
sbquo: '\u201A',
|
||||
ldquo: '\u201C',
|
||||
rdquo: '\u201D',
|
||||
bdquo: '\u201E',
|
||||
dagger: '\u2020',
|
||||
Dagger: '\u2021',
|
||||
bull: '\u2022',
|
||||
hellip: '\u2026',
|
||||
permil: '\u2030',
|
||||
prime: '\u2032',
|
||||
Prime: '\u2033',
|
||||
lsaquo: '\u2039',
|
||||
rsaquo: '\u203A',
|
||||
oline: '\u203E',
|
||||
frasl: '\u2044',
|
||||
euro: '\u20AC',
|
||||
image: '\u2111',
|
||||
weierp: '\u2118',
|
||||
real: '\u211C',
|
||||
trade: '\u2122',
|
||||
alefsym: '\u2135',
|
||||
larr: '\u2190',
|
||||
uarr: '\u2191',
|
||||
rarr: '\u2192',
|
||||
darr: '\u2193',
|
||||
harr: '\u2194',
|
||||
crarr: '\u21B5',
|
||||
lArr: '\u21D0',
|
||||
uArr: '\u21D1',
|
||||
rArr: '\u21D2',
|
||||
dArr: '\u21D3',
|
||||
hArr: '\u21D4',
|
||||
forall: '\u2200',
|
||||
part: '\u2202',
|
||||
exist: '\u2203',
|
||||
empty: '\u2205',
|
||||
nabla: '\u2207',
|
||||
isin: '\u2208',
|
||||
notin: '\u2209',
|
||||
ni: '\u220B',
|
||||
prod: '\u220F',
|
||||
sum: '\u2211',
|
||||
minus: '\u2212',
|
||||
lowast: '\u2217',
|
||||
radic: '\u221A',
|
||||
prop: '\u221D',
|
||||
infin: '\u221E',
|
||||
ang: '\u2220',
|
||||
and: '\u2227',
|
||||
or: '\u2228',
|
||||
cap: '\u2229',
|
||||
cup: '\u222A',
|
||||
'int': '\u222B',
|
||||
there4: '\u2234',
|
||||
sim: '\u223C',
|
||||
cong: '\u2245',
|
||||
asymp: '\u2248',
|
||||
ne: '\u2260',
|
||||
equiv: '\u2261',
|
||||
le: '\u2264',
|
||||
ge: '\u2265',
|
||||
sub: '\u2282',
|
||||
sup: '\u2283',
|
||||
nsub: '\u2284',
|
||||
sube: '\u2286',
|
||||
supe: '\u2287',
|
||||
oplus: '\u2295',
|
||||
otimes: '\u2297',
|
||||
perp: '\u22A5',
|
||||
sdot: '\u22C5',
|
||||
lceil: '\u2308',
|
||||
rceil: '\u2309',
|
||||
lfloor: '\u230A',
|
||||
rfloor: '\u230B',
|
||||
lang: '\u2329',
|
||||
rang: '\u232A',
|
||||
loz: '\u25CA',
|
||||
spades: '\u2660',
|
||||
clubs: '\u2663',
|
||||
hearts: '\u2665',
|
||||
diams: '\u2666'
|
||||
};
|
||||
|
||||
var hexNumber = /^[\da-fA-F]+$/;
|
||||
var decimalNumber = /^\d+$/;
|
||||
|
||||
pp.jsx_readEntity = function() {
|
||||
var str = "", count = 0, entity;
|
||||
var ch = this.input[this.pos];
|
||||
if (ch !== "&")
|
||||
this.raise(this.pos, "Entity must start with an ampersand");
|
||||
var startPos = ++this.pos;
|
||||
while (this.pos < this.input.length && count++ < 10) {
|
||||
ch = this.input[this.pos++];
|
||||
if (ch === ";") {
|
||||
if (str[0] === "#") {
|
||||
if (str[1] === "x") {
|
||||
str = str.substr(2);
|
||||
if (hexNumber.test(str))
|
||||
entity = String.fromCharCode(parseInt(str, 16));
|
||||
} else {
|
||||
str = str.substr(1);
|
||||
if (decimalNumber.test(str))
|
||||
entity = String.fromCharCode(parseInt(str, 10));
|
||||
}
|
||||
} else {
|
||||
entity = XHTMLEntities[str];
|
||||
}
|
||||
break;
|
||||
}
|
||||
str += ch;
|
||||
}
|
||||
if (!entity) {
|
||||
this.pos = startPos;
|
||||
return "&";
|
||||
}
|
||||
return entity;
|
||||
};
|
||||
|
||||
|
||||
// Read a JSX identifier (valid tag or attribute name).
|
||||
//
|
||||
// Optimized version since JSX identifiers can't contain
|
||||
// escape characters and so can be read as single slice.
|
||||
// Also assumes that first character was already checked
|
||||
// by isIdentifierStart in readToken.
|
||||
|
||||
pp.jsx_readWord = function() {
|
||||
var ch, start = this.pos;
|
||||
do {
|
||||
ch = this.input.charCodeAt(++this.pos);
|
||||
} while (acorn.isIdentifierChar(ch) || ch === 45); // '-'
|
||||
return this.finishToken(tt.jsxName, this.input.slice(start, this.pos));
|
||||
};
|
||||
|
||||
// Transforms JSX element name to string.
|
||||
|
||||
function getQualifiedJSXName(object) {
|
||||
if (object.type === "JSXIdentifier")
|
||||
return object.name;
|
||||
|
||||
if (object.type === "JSXNamespacedName")
|
||||
return object.namespace.name + ':' + object.name.name;
|
||||
|
||||
if (object.type === "JSXMemberExpression")
|
||||
return getQualifiedJSXName(object.object) + '.' +
|
||||
getQualifiedJSXName(object.property);
|
||||
}
|
||||
|
||||
// Parse next token as JSX identifier
|
||||
|
||||
pp.jsx_parseIdentifier = function() {
|
||||
var node = this.startNode();
|
||||
if (this.type === tt.jsxName)
|
||||
node.name = this.value;
|
||||
else if (this.type.keyword)
|
||||
node.name = this.type.keyword;
|
||||
else
|
||||
this.unexpected();
|
||||
this.next();
|
||||
return this.finishNode(node, "JSXIdentifier");
|
||||
};
|
||||
|
||||
// Parse namespaced identifier.
|
||||
|
||||
pp.jsx_parseNamespacedName = function() {
|
||||
var start = this.markPosition();
|
||||
var name = this.jsx_parseIdentifier();
|
||||
if (!this.eat(tt.colon)) return name;
|
||||
var node = this.startNodeAt(start);
|
||||
node.namespace = name;
|
||||
node.name = this.jsx_parseIdentifier();
|
||||
return this.finishNode(node, "JSXNamespacedName");
|
||||
};
|
||||
|
||||
// Parses element name in any form - namespaced, member
|
||||
// or single identifier.
|
||||
|
||||
pp.jsx_parseElementName = function() {
|
||||
var start = this.markPosition();
|
||||
var node = this.jsx_parseNamespacedName();
|
||||
while (this.eat(tt.dot)) {
|
||||
var newNode = this.startNodeAt(start);
|
||||
newNode.object = node;
|
||||
newNode.property = this.jsx_parseIdentifier();
|
||||
node = this.finishNode(newNode, "JSXMemberExpression");
|
||||
}
|
||||
return node;
|
||||
};
|
||||
|
||||
// Parses any type of JSX attribute value.
|
||||
|
||||
pp.jsx_parseAttributeValue = function() {
|
||||
switch (this.type) {
|
||||
case tt.braceL:
|
||||
var node = this.jsx_parseExpressionContainer();
|
||||
if (node.expression.type === "JSXEmptyExpression")
|
||||
this.raise(node.start, "JSX attributes must only be assigned a non-empty expression");
|
||||
return node;
|
||||
|
||||
case tt.jsxTagStart:
|
||||
case tt.string:
|
||||
return this.parseExprAtom();
|
||||
|
||||
default:
|
||||
this.raise(this.start, "JSX value should be either an expression or a quoted JSX text");
|
||||
}
|
||||
};
|
||||
|
||||
// JSXEmptyExpression is unique type since it doesn't actually parse anything,
|
||||
// and so it should start at the end of last read token (left brace) and finish
|
||||
// at the beginning of the next one (right brace).
|
||||
|
||||
pp.jsx_parseEmptyExpression = function() {
|
||||
var tmp = this.start;
|
||||
this.start = this.lastTokEnd;
|
||||
this.lastTokEnd = tmp;
|
||||
|
||||
tmp = this.startLoc;
|
||||
this.startLoc = this.lastTokEndLoc;
|
||||
this.lastTokEndLoc = tmp;
|
||||
|
||||
return this.finishNode(this.startNode(), "JSXEmptyExpression");
|
||||
};
|
||||
|
||||
// Parses JSX expression enclosed into curly brackets.
|
||||
|
||||
|
||||
pp.jsx_parseExpressionContainer = function() {
|
||||
var node = this.startNode();
|
||||
this.next();
|
||||
node.expression = this.type === tt.braceR
|
||||
? this.jsx_parseEmptyExpression()
|
||||
: this.parseExpression();
|
||||
this.expect(tt.braceR);
|
||||
return this.finishNode(node, "JSXExpressionContainer");
|
||||
};
|
||||
|
||||
// Parses following JSX attribute name-value pair.
|
||||
|
||||
pp.jsx_parseAttribute = function() {
|
||||
var node = this.startNode();
|
||||
if (this.eat(tt.braceL)) {
|
||||
this.expect(tt.ellipsis);
|
||||
node.argument = this.parseMaybeAssign();
|
||||
this.expect(tt.braceR);
|
||||
return this.finishNode(node, "JSXSpreadAttribute");
|
||||
}
|
||||
node.name = this.jsx_parseNamespacedName();
|
||||
node.value = this.eat(tt.eq) ? this.jsx_parseAttributeValue() : null;
|
||||
return this.finishNode(node, "JSXAttribute");
|
||||
};
|
||||
|
||||
// Parses JSX opening tag starting after '<'.
|
||||
|
||||
pp.jsx_parseOpeningElementAt = function(start) {
|
||||
var node = this.startNodeAt(start);
|
||||
node.attributes = [];
|
||||
node.name = this.jsx_parseElementName();
|
||||
while (this.type !== tt.slash && this.type !== tt.jsxTagEnd)
|
||||
node.attributes.push(this.jsx_parseAttribute());
|
||||
node.selfClosing = this.eat(tt.slash);
|
||||
this.expect(tt.jsxTagEnd);
|
||||
return this.finishNode(node, "JSXOpeningElement");
|
||||
};
|
||||
|
||||
// Parses JSX closing tag starting after '</'.
|
||||
|
||||
pp.jsx_parseClosingElementAt = function(start) {
|
||||
var node = this.startNodeAt(start);
|
||||
node.name = this.jsx_parseElementName();
|
||||
this.expect(tt.jsxTagEnd);
|
||||
return this.finishNode(node, "JSXClosingElement");
|
||||
};
|
||||
|
||||
// Parses entire JSX element, including it's opening tag
|
||||
// (starting after '<'), attributes, contents and closing tag.
|
||||
|
||||
pp.jsx_parseElementAt = function(start) {
|
||||
var node = this.startNodeAt(start);
|
||||
var children = [];
|
||||
var openingElement = this.jsx_parseOpeningElementAt(start);
|
||||
var closingElement = null;
|
||||
|
||||
if (!openingElement.selfClosing) {
|
||||
contents: for (;;) {
|
||||
switch (this.type) {
|
||||
case tt.jsxTagStart:
|
||||
start = this.markPosition();
|
||||
this.next();
|
||||
if (this.eat(tt.slash)) {
|
||||
closingElement = this.jsx_parseClosingElementAt(start);
|
||||
break contents;
|
||||
}
|
||||
children.push(this.jsx_parseElementAt(start));
|
||||
break;
|
||||
|
||||
case tt.jsxText:
|
||||
children.push(this.parseExprAtom());
|
||||
break;
|
||||
|
||||
case tt.braceL:
|
||||
children.push(this.jsx_parseExpressionContainer());
|
||||
break;
|
||||
|
||||
default:
|
||||
this.unexpected();
|
||||
}
|
||||
}
|
||||
if (getQualifiedJSXName(closingElement.name) !== getQualifiedJSXName(openingElement.name))
|
||||
this.raise(
|
||||
closingElement.start,
|
||||
"Expected corresponding JSX closing tag for <" + getQualifiedJSXName(openingElement.name) + ">");
|
||||
}
|
||||
|
||||
node.openingElement = openingElement;
|
||||
node.closingElement = closingElement;
|
||||
node.children = children;
|
||||
return this.finishNode(node, "JSXElement");
|
||||
};
|
||||
|
||||
// Parses entire JSX element from current position.
|
||||
|
||||
pp.jsx_parseElement = function() {
|
||||
var start = this.markPosition();
|
||||
this.next();
|
||||
return this.jsx_parseElementAt(start);
|
||||
};
|
||||
|
||||
acorn.plugins.jsx = function(instance) {
|
||||
instance.extend("parseExprAtom", function(inner) {
|
||||
return function(refShortHandDefaultPos) {
|
||||
if (this.type === tt.jsxText)
|
||||
return this.parseLiteral(this.value);
|
||||
else if (this.type === tt.jsxTagStart)
|
||||
return this.jsx_parseElement();
|
||||
else
|
||||
return inner.call(this, refShortHandDefaultPos);
|
||||
};
|
||||
});
|
||||
|
||||
instance.extend("readToken", function(inner) {
|
||||
return function(code) {
|
||||
var context = this.curContext();
|
||||
|
||||
if (context === tc.j_expr) return this.jsx_readToken();
|
||||
|
||||
if (context === tc.j_oTag || context === tc.j_cTag) {
|
||||
if (acorn.isIdentifierStart(code)) return this.jsx_readWord();
|
||||
|
||||
if (code == 62) {
|
||||
++this.pos;
|
||||
return this.finishToken(tt.jsxTagEnd);
|
||||
}
|
||||
|
||||
if ((code === 34 || code === 39) && context == tc.j_oTag)
|
||||
return this.jsx_readString(code);
|
||||
}
|
||||
|
||||
if (code === 60 && this.exprAllowed) {
|
||||
++this.pos;
|
||||
return this.finishToken(tt.jsxTagStart);
|
||||
}
|
||||
return inner.call(this, code);
|
||||
};
|
||||
});
|
||||
|
||||
instance.extend("updateContext", function(inner) {
|
||||
return function(prevType) {
|
||||
if (this.type == tt.braceL) {
|
||||
var curContext = this.curContext();
|
||||
if (curContext == tc.j_oTag) this.context.push(tc.b_expr);
|
||||
else if (curContext == tc.j_expr) this.context.push(tc.b_tmpl);
|
||||
else inner.call(this, prevType);
|
||||
this.exprAllowed = true;
|
||||
} else if (this.type === tt.slash && prevType === tt.jsxTagStart) {
|
||||
this.context.length -= 2; // do not consider JSX expr -> JSX open tag -> ... anymore
|
||||
this.context.push(tc.j_cTag); // reconsider as closing tag context
|
||||
this.exprAllowed = false;
|
||||
} else {
|
||||
return inner.call(this, prevType);
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
require("./node");
|
||||
var transform = module.exports = require("../transformation");
|
||||
|
||||
transform.options = require("../transformation/file/options");
|
||||
|
||||
@@ -5,11 +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 Pipeline } from "../transformation/transformer-pipeline";
|
||||
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";
|
||||
@@ -52,10 +53,11 @@ export function transformFile(filename: string, opts?: Object, callback: Functio
|
||||
|
||||
export function transformFileSync(filename: string, opts?: Object = {}) {
|
||||
opts.filename = filename;
|
||||
return transform(fs.readFileSync(filename), opts);
|
||||
return transform(fs.readFileSync(filename, "utf8"), opts);
|
||||
}
|
||||
|
||||
export function parse(code, opts = {}) {
|
||||
opts.allowHashBang = true;
|
||||
opts.sourceType = "module";
|
||||
opts.ecmaVersion = Infinity;
|
||||
opts.plugins = {
|
||||
@@ -64,7 +66,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;
|
||||
}
|
||||
|
||||
|
||||
@@ -87,7 +87,7 @@ var shouldIgnore = function (filename) {
|
||||
|
||||
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
|
||||
// what istanbul gets, it's extremely dirty but it's the only way
|
||||
var _readFileSync = fs.readFileSync;
|
||||
@@ -117,7 +117,7 @@ var registerExtension = function (ext) {
|
||||
var old = oldHandlers[ext] || oldHandlers[".js"];
|
||||
|
||||
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) {
|
||||
if (shouldIgnore(filename)) {
|
||||
|
||||
@@ -232,14 +232,14 @@ class CodeGenerator {
|
||||
this.map.mark(node, "end");
|
||||
if (opts.after) opts.after();
|
||||
|
||||
this.format.concise = oldConcise;
|
||||
|
||||
newline(false);
|
||||
|
||||
this.printTrailingComments(node, parent);
|
||||
} else {
|
||||
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 = {}) {
|
||||
|
||||
@@ -1,65 +1,34 @@
|
||||
import normalizeAst from "./normalize-ast";
|
||||
import estraverse from "estraverse";
|
||||
import codeFrame from "./code-frame";
|
||||
import * as acorn from "../../acorn";
|
||||
|
||||
export default function (opts, code, callback) {
|
||||
try {
|
||||
var comments = [];
|
||||
var tokens = [];
|
||||
export default function (code, opts = {}) {
|
||||
var comments = [];
|
||||
var tokens = [];
|
||||
|
||||
var parseOpts = {
|
||||
allowImportExportEverywhere: opts.looseModules,
|
||||
allowReturnOutsideFunction: opts.looseModules,
|
||||
ecmaVersion: 6,
|
||||
strictMode: opts.strictMode,
|
||||
sourceType: opts.sourceType,
|
||||
onComment: comments,
|
||||
locations: true,
|
||||
features: opts.features || {},
|
||||
plugins: opts.plugins || {},
|
||||
onToken: tokens,
|
||||
ranges: true
|
||||
};
|
||||
var parseOpts = {
|
||||
allowImportExportEverywhere: opts.looseModules,
|
||||
allowReturnOutsideFunction: opts.looseModules,
|
||||
allowHashBang: true,
|
||||
ecmaVersion: 6,
|
||||
strictMode: opts.strictMode,
|
||||
sourceType: opts.sourceType,
|
||||
locations: true,
|
||||
onComment: comments,
|
||||
features: opts.features || {},
|
||||
plugins: opts.plugins || {},
|
||||
onToken: tokens,
|
||||
ranges: true
|
||||
};
|
||||
|
||||
if (opts.nonStandard) {
|
||||
parseOpts.plugins.jsx = 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;
|
||||
if (opts.nonStandard) {
|
||||
parseOpts.plugins.jsx = true;
|
||||
parseOpts.plugins.flow = true;
|
||||
}
|
||||
};
|
||||
|
||||
var ast = acorn.parse(code, parseOpts);
|
||||
|
||||
estraverse.attachComments(ast, comments, tokens);
|
||||
ast = normalizeAst(ast, comments, tokens);
|
||||
return ast;
|
||||
}
|
||||
|
||||
@@ -23,10 +23,12 @@ export const MESSAGES = {
|
||||
missingTemplatesDirectory: "no templates directory - this is most likely the result of a broken `npm publish`. Please report to https://github.com/babel/babel/issues",
|
||||
unsupportedOutputType: "Unsupported output type $1",
|
||||
illegalMethodName: "Illegal method name $1",
|
||||
|
||||
traverseNeedsParent: "Must pass a scope and parentPath unless traversing a Program/File got a $1 node",
|
||||
traverseVerifyRootFunction: "You passed `traverse()` a function when it expected a visitor object, are you sure you didn't mean `{ enter: Function }`?",
|
||||
traverseVerifyVisitorFunction: "Hey! You passed \`traverse()\` a visitor object with the key $1 that's a straight up `Function` instead of `{ enter: Function }`. You need to normalise it with `traverse.explode(visitor)`.",
|
||||
traverseVerifyVisitorFunction: "You passed \`traverse()\` a visitor object with the key $1 that's a `Function` instead of `{ enter: Function }`. You need to normalise your visitor with `traverse.explode(visitor)`.",
|
||||
traverseVerifyVisitorProperty: "You passed `traverse()` a visitor object with the property $1 that has the invalid property $2",
|
||||
traverseVerifyNodeType: "You gave us a visitor for the node type $1 but it's not a valid type",
|
||||
|
||||
pluginIllegalKind: "Illegal kind $1 for plugin $2",
|
||||
pluginIllegalPosition: "Illegal position $1 for plugin $2",
|
||||
|
||||
@@ -10,6 +10,7 @@ import resolveRc from "../../tools/resolve-rc";
|
||||
import sourceMap from "source-map";
|
||||
import transform from "./../index";
|
||||
import generate from "../../generation";
|
||||
import codeFrame from "../../helpers/code-frame";
|
||||
import defaults from "lodash/object/defaults";
|
||||
import includes from "lodash/collection/includes";
|
||||
import traverse from "../../traversal";
|
||||
@@ -236,48 +237,6 @@ export default class File {
|
||||
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 {
|
||||
return this.data[key] = val;
|
||||
};
|
||||
@@ -370,13 +329,24 @@ export default class File {
|
||||
}
|
||||
|
||||
var ref = util.template("helper-" + name);
|
||||
ref._compact = true;
|
||||
|
||||
var uid = this.declarations[name] = this.scope.generateUidIdentifier(name);
|
||||
this.scope.push({
|
||||
id: uid,
|
||||
init: ref,
|
||||
unique: true
|
||||
});
|
||||
|
||||
if (t.isFunctionExpression(ref) && !ref.id) {
|
||||
ref.body._compact = 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;
|
||||
}
|
||||
|
||||
@@ -387,110 +357,6 @@ export default class File {
|
||||
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) {
|
||||
if (Array.isArray(path)) {
|
||||
for (var i = 0; i < path.length; i++) {
|
||||
@@ -530,6 +396,180 @@ export default class File {
|
||||
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) {
|
||||
code = code + "";
|
||||
|
||||
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(): {
|
||||
usedHelpers?: Array<string>;
|
||||
code: string;
|
||||
|
||||
@@ -25,6 +25,10 @@
|
||||
"type": "string"
|
||||
},
|
||||
|
||||
"getModuleId": {
|
||||
"hidden": true
|
||||
},
|
||||
|
||||
"retainLines": {
|
||||
"hidden": true,
|
||||
"type": "boolean",
|
||||
|
||||
@@ -10,14 +10,14 @@ import * as react from "./react";
|
||||
import * as t from "../../types";
|
||||
|
||||
export default function (exports, opts) {
|
||||
exports.check = function (node) {
|
||||
exports.shouldVisit = function (node) {
|
||||
if (t.isJSX(node)) return true;
|
||||
if (react.isCreateClass(node)) return true;
|
||||
return false;
|
||||
};
|
||||
|
||||
exports.JSXIdentifier = function (node, parent) {
|
||||
if (node.name === "this" && t.isReferenced(node, parent)) {
|
||||
if (node.name === "this" && this.isReferenced()) {
|
||||
return t.thisExpression();
|
||||
} else if (esutils.keyword.isIdentifierNameES6(node.name)) {
|
||||
node.type = "Identifier";
|
||||
|
||||
@@ -19,7 +19,7 @@ var awaitVisitor = {
|
||||
var referenceVisitor = {
|
||||
enter(node, parent, scope, state) {
|
||||
var name = state.id.name;
|
||||
if (t.isReferencedIdentifier(node, parent, { name: name }) && scope.bindingIdentifierEquals(name, state.id)) {
|
||||
if (this.isReferencedIdentifier({ name: name }) && scope.bindingIdentifierEquals(name, state.id)) {
|
||||
return state.ref = state.ref || scope.generateUidIdentifier(name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ pipeline.addDeprecated(deprecated);
|
||||
//
|
||||
|
||||
import aliases from "./transformers/aliases";
|
||||
pipeline.addDeprecated(aliases);
|
||||
pipeline.addAliases(aliases);
|
||||
|
||||
//
|
||||
|
||||
|
||||
@@ -5,61 +5,65 @@ import object from "../../helpers/object";
|
||||
import * as util from "../../util";
|
||||
import * as t from "../../types";
|
||||
|
||||
var remapVisitor = {
|
||||
var remapVisitor = traverse.explode({
|
||||
enter(node, parent, scope, formatter) {
|
||||
var remap = formatter.internalRemap[node.name];
|
||||
if (this.isReferencedIdentifier() && remap) {
|
||||
if (!scope.hasBinding(node.name) || scope.bindingIdentifierEquals(node.name, formatter.localImports[node.name])) {
|
||||
return remap;
|
||||
}
|
||||
}
|
||||
|
||||
if (t.isUpdateExpression(node)) {
|
||||
var exported = formatter.getExport(node.argument, scope);
|
||||
|
||||
if (exported) {
|
||||
this.skip();
|
||||
|
||||
// expand to long file assignment expression
|
||||
var assign = t.assignmentExpression(node.operator[0] + "=", node.argument, t.literal(1));
|
||||
|
||||
// remap this assignment expression
|
||||
var remapped = formatter.remapExportAssignment(assign, exported);
|
||||
|
||||
// we don't need to change the result
|
||||
if (t.isExpressionStatement(parent) || node.prefix) {
|
||||
return remapped;
|
||||
}
|
||||
|
||||
var nodes = [];
|
||||
nodes.push(remapped);
|
||||
|
||||
var operator;
|
||||
if (node.operator === "--") {
|
||||
operator = "+";
|
||||
} else { // "++"
|
||||
operator = "-";
|
||||
}
|
||||
nodes.push(t.binaryExpression(operator, node.argument, t.literal(1)));
|
||||
|
||||
return t.sequenceExpression(nodes);
|
||||
}
|
||||
}
|
||||
|
||||
if (node._skipModulesRemap) {
|
||||
return this.skip();
|
||||
}
|
||||
},
|
||||
|
||||
exit(node, parent, scope, formatter) {
|
||||
if (t.isAssignmentExpression(node) && !node._ignoreModulesRemap) {
|
||||
var exported = formatter.getExport(node.left, scope);
|
||||
if (exported) {
|
||||
return formatter.remapExportAssignment(node, exported);
|
||||
Identifier(node, parent, scope, formatter) {
|
||||
var remap = formatter.internalRemap[node.name];
|
||||
|
||||
if (this.isReferencedIdentifier() && remap && node !== remap) {
|
||||
if (!scope.hasBinding(node.name) || scope.bindingIdentifierEquals(node.name, formatter.localImports[node.name])) {
|
||||
return remap;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
AssignmentExpression: {
|
||||
exit(node, parent, scope, formatter) {
|
||||
if (!node._ignoreModulesRemap) {
|
||||
var exported = formatter.getExport(node.left, scope);
|
||||
if (exported) {
|
||||
return formatter.remapExportAssignment(node, exported);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
UpdateExpression(node, parent, scope, formatter) {
|
||||
var exported = formatter.getExport(node.argument, scope);
|
||||
if (!exported) return;
|
||||
|
||||
this.skip();
|
||||
|
||||
// expand to long file assignment expression
|
||||
var assign = t.assignmentExpression(node.operator[0] + "=", node.argument, t.literal(1));
|
||||
|
||||
// remap this assignment expression
|
||||
var remapped = formatter.remapExportAssignment(assign, exported);
|
||||
|
||||
// we don't need to change the result
|
||||
if (t.isExpressionStatement(parent) || node.prefix) {
|
||||
return remapped;
|
||||
}
|
||||
|
||||
var nodes = [];
|
||||
nodes.push(remapped);
|
||||
|
||||
var operator;
|
||||
if (node.operator === "--") {
|
||||
operator = "+";
|
||||
} else { // "++"
|
||||
operator = "-";
|
||||
}
|
||||
nodes.push(t.binaryExpression(operator, node.argument, t.literal(1)));
|
||||
|
||||
return t.sequenceExpression(nodes);
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
var importsVisitor = {
|
||||
ImportDeclaration: {
|
||||
@@ -184,7 +188,10 @@ export default class DefaultFormatter {
|
||||
|
||||
getModuleName() {
|
||||
var opts = this.file.opts;
|
||||
if (opts.moduleId) return opts.moduleId;
|
||||
// moduleId is n/a if a `getModuleId()` is provided
|
||||
if (opts.moduleId && !opts.getModuleId) {
|
||||
return opts.moduleId;
|
||||
}
|
||||
|
||||
var filenameRelative = opts.filenameRelative;
|
||||
var moduleName = "";
|
||||
@@ -213,7 +220,12 @@ export default class DefaultFormatter {
|
||||
// normalize path separators
|
||||
moduleName = moduleName.replace(/\\/g, "/");
|
||||
|
||||
return moduleName;
|
||||
if (opts.getModuleId) {
|
||||
// If return is falsy, assume they want us to use our generated default name
|
||||
return opts.getModuleId(moduleName) || moduleName;
|
||||
} else {
|
||||
return moduleName;
|
||||
}
|
||||
}
|
||||
|
||||
_pushStatement(ref, nodes) {
|
||||
|
||||
@@ -23,7 +23,7 @@ export default class AMDFormatter extends DefaultFormatter {
|
||||
*/
|
||||
|
||||
transform(program) {
|
||||
DefaultFormatter.prototype.transform.apply(this, arguments);
|
||||
CommonFormatter.prototype.transform.apply(this, arguments);
|
||||
|
||||
var body = program.body;
|
||||
|
||||
@@ -108,12 +108,16 @@ export default class AMDFormatter extends DefaultFormatter {
|
||||
exportSpecifier(specifier, node, nodes) {
|
||||
if (this.doDefaultExportInterop(specifier)) {
|
||||
this.passModuleArg = true;
|
||||
nodes.push(util.template("exports-default-assign", {
|
||||
VALUE: specifier.local
|
||||
}, true));
|
||||
} else {
|
||||
CommonFormatter.prototype.exportSpecifier.apply(this, arguments);
|
||||
|
||||
if (specifier.exported !== specifier.local && !node.source) {
|
||||
nodes.push(util.template("exports-default-assign", {
|
||||
VALUE: specifier.local
|
||||
}, true));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
CommonFormatter.prototype.exportSpecifier.apply(this, arguments);
|
||||
}
|
||||
|
||||
exportDeclaration(node, nodes) {
|
||||
|
||||
@@ -57,16 +57,19 @@ export default class TransformerPipeline {
|
||||
|
||||
transform(code: string, opts?: Object) {
|
||||
var file = new File(opts, this);
|
||||
return file.parse(code);
|
||||
return file.wrap(code, function () {
|
||||
file.addCode(code, true);
|
||||
});
|
||||
}
|
||||
|
||||
transformFromAst(ast, code, opts) {
|
||||
ast = normalizeAst(ast);
|
||||
|
||||
var file = new File(opts, this);
|
||||
file.addCode(code);
|
||||
file.transform(ast);
|
||||
return file.generate();
|
||||
return file.wrap(code, function () {
|
||||
file.addCode(code);
|
||||
file.addAst(ast);
|
||||
});
|
||||
}
|
||||
|
||||
_ensureTransformerNames(type: string, rawKeys: Array<string>) {
|
||||
@@ -81,7 +84,7 @@ export default class TransformerPipeline {
|
||||
keys.push(aliasKey);
|
||||
} else if (deprecatedKey) {
|
||||
// deprecated key, remap it to the new one
|
||||
console.error(`The transformer ${key} has been renamed to ${deprecatedKey}`);
|
||||
console.error(`[BABEL] The transformer ${key} has been renamed to ${deprecatedKey}`);
|
||||
rawKeys.push(deprecatedKey);
|
||||
} else if (this.transformers[key]) {
|
||||
// valid key
|
||||
|
||||
@@ -44,7 +44,7 @@ export default class Transformer {
|
||||
|
||||
//
|
||||
|
||||
if (!this.shouldVisit) {
|
||||
if (!this.shouldVisit && !this.handlers.enter && !this.handlers.exit) {
|
||||
var types = Object.keys(this.handlers);
|
||||
this.shouldVisit = function (node) {
|
||||
for (var i = 0; i < types.length; i++) {
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
"es6.symbols": "es6.spec.symbols",
|
||||
"es6.blockScopingTDZ": "es6.spec.blockScoping",
|
||||
|
||||
"minification.deadCodeElimination": "utility.deadCodeElimination",
|
||||
"utility.deadCodeElimination": "minification.deadCodeElimination",
|
||||
"minification.removeConsoleCalls": "utility.removeConsole",
|
||||
"minification.removeDebugger": "utility.removeDebugger"
|
||||
}
|
||||
|
||||
@@ -2,11 +2,7 @@ import * as t from "../../../types";
|
||||
|
||||
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;
|
||||
} else if (!node.computed && t.isIdentifier(prop) && !t.isValidIdentifier(prop.name)) {
|
||||
if (!node.computed && t.isIdentifier(prop) && !t.isValidIdentifier(prop.name)) {
|
||||
// foo.default -> foo["default"]
|
||||
node.property = t.literal(prop.name);
|
||||
node.computed = true;
|
||||
|
||||
@@ -2,11 +2,7 @@ import * as t from "../../../types";
|
||||
|
||||
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;
|
||||
} else if (!node.computed && t.isIdentifier(key) && !t.isValidIdentifier(key.name)) {
|
||||
if (!node.computed && t.isIdentifier(key) && !t.isValidIdentifier(key.name)) {
|
||||
// default: "bar" -> "default": "bar"
|
||||
node.key = t.literal(key.name);
|
||||
}
|
||||
|
||||
@@ -8,6 +8,4 @@ export function ArrowFunctionExpression(node) {
|
||||
node.expression = false;
|
||||
node.type = "FunctionExpression";
|
||||
node.shadow = true;
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
@@ -96,10 +96,6 @@ var verifyConstructorVisitor = traverse.explode({
|
||||
if (state.hasSuper && !state.hasBareSuper) {
|
||||
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;
|
||||
|
||||
//
|
||||
@@ -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) {
|
||||
// named class with only a constructor
|
||||
if (body.length === 1) return t.toExpression(body[0]);
|
||||
@@ -344,9 +325,7 @@ class ClassTransformer {
|
||||
if (!this.hasConstructor && this.hasSuper) {
|
||||
var helperName = "class-super-constructor-call";
|
||||
if (this.isLoose) helperName += "-loose";
|
||||
if (this.isNativeSuper) helperName = "class-super-native-constructor-call";
|
||||
constructorBody.body.push(util.template(helperName, {
|
||||
NATIVE_REF: this.nativeSuperRef,
|
||||
CLASS_NAME: this.classRef,
|
||||
SUPER_NAME: this.superName
|
||||
}, true));
|
||||
@@ -475,12 +454,10 @@ class ClassTransformer {
|
||||
|
||||
verifyConstructor(path: TraversalPath) {
|
||||
var state = {
|
||||
nativeSuperRef: this.nativeSuperRef,
|
||||
isNativeSuper: this.isNativeSuper,
|
||||
hasBareSuper: false,
|
||||
bareSuper: null,
|
||||
hasSuper: this.hasSuper,
|
||||
file: this.file
|
||||
hasBareSuper: false,
|
||||
bareSuper: null,
|
||||
hasSuper: this.hasSuper,
|
||||
file: this.file
|
||||
};
|
||||
|
||||
path.get("value").traverse(verifyConstructorVisitor, state);
|
||||
@@ -490,22 +467,7 @@ class ClassTransformer {
|
||||
if (!state.hasBareSuper && this.hasSuper) {
|
||||
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.
|
||||
@@ -605,10 +567,6 @@ class ClassTransformer {
|
||||
fnPath.scope.rename(this.classRef.name);
|
||||
}
|
||||
|
||||
if (this.isNativeSuper) {
|
||||
fnPath.traverse(constructorVisitor, this.nativeSuperRef);
|
||||
}
|
||||
|
||||
var construct = this.constructor;
|
||||
var fn = method.value;
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@ exports.Function = function (node, parent, scope, file) {
|
||||
|
||||
var block = node.body;
|
||||
block.body = nodes.concat(block.body);
|
||||
return node;
|
||||
this.checkSelf();
|
||||
};
|
||||
|
||||
export function CatchClause(node, parent, scope, file) {
|
||||
@@ -104,7 +104,7 @@ export function CatchClause(node, parent, scope, file) {
|
||||
|
||||
node.body.body = nodes.concat(node.body.body);
|
||||
|
||||
return node;
|
||||
this.checkSelf();
|
||||
}
|
||||
|
||||
export function ExpressionStatement(node, parent, scope, file) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import * as t from "../../../types";
|
||||
|
||||
export { check } from "../internal/modules";
|
||||
export { shouldVisit } from "../internal/modules";
|
||||
|
||||
function keepBlockHoist(node, nodes) {
|
||||
if (node._blockHoist) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import callDelegate from "../../helpers/call-delegate";
|
||||
import * as util from "../../../util";
|
||||
import traverse from "../../../traversal";
|
||||
import * as t from "../../../types";
|
||||
|
||||
export function shouldVisit(node) {
|
||||
@@ -13,16 +14,15 @@ var hasDefaults = function (node) {
|
||||
return false;
|
||||
};
|
||||
|
||||
var iifeVisitor = {
|
||||
enter(node, parent, scope, state) {
|
||||
if (!this.isReferencedIdentifier()) return;
|
||||
var iifeVisitor = traverse.explode({
|
||||
ReferencedIdentifier(node, parent, scope, state) {
|
||||
if (!state.scope.hasOwnBinding(node.name)) return;
|
||||
if (state.scope.bindingIdentifierEquals(node.name, node)) return;
|
||||
|
||||
state.iife = true;
|
||||
this.stop();
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
exports.Function = function (node, parent, scope, file) {
|
||||
if (!hasDefaults(node)) return;
|
||||
@@ -97,5 +97,5 @@ exports.Function = function (node, parent, scope, file) {
|
||||
node.body.body = body.concat(node.body.body);
|
||||
}
|
||||
|
||||
return node;
|
||||
this.checkSelf();
|
||||
};
|
||||
|
||||
@@ -96,7 +96,8 @@ exports.Function = function (node, parent, scope, file) {
|
||||
candidate.replaceWith(argsId);
|
||||
optimizeMemberExpression(candidate.parent, node.params.length);
|
||||
}
|
||||
return node;
|
||||
this.checkSelf();
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
@@ -137,5 +138,5 @@ exports.Function = function (node, parent, scope, file) {
|
||||
});
|
||||
loop._blockHoist = node.params.length + 1;
|
||||
node.body.body.unshift(loop);
|
||||
return node;
|
||||
this.checkSelf();
|
||||
};
|
||||
|
||||
@@ -16,27 +16,13 @@ function loose(node, body, objId) {
|
||||
|
||||
function spec(node, body, objId, initProps, file) {
|
||||
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
|
||||
|
||||
var broken = false;
|
||||
|
||||
for (i = 0; i < props.length; i++) {
|
||||
prop = props[i];
|
||||
for (let i = 0; i < props.length; i++) {
|
||||
let prop = props[i];
|
||||
|
||||
if (prop.computed) {
|
||||
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
|
||||
// otherwise use Object.defineProperty
|
||||
|
||||
for (i = 0; i < props.length; i++) {
|
||||
prop = props[i];
|
||||
for (let i = 0; i < props.length; i++) {
|
||||
let prop = props[i];
|
||||
if (!prop) continue;
|
||||
|
||||
key = prop.key;
|
||||
var bodyNode;
|
||||
|
||||
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]);
|
||||
let key = prop.key;
|
||||
if (t.isIdentifier(key) && !prop.computed) {
|
||||
key = t.literal(key.name);
|
||||
}
|
||||
|
||||
var bodyNode = t.callExpression(file.addHelper("define-property"), [objId, key, prop.value]);
|
||||
|
||||
body.push(t.expressionStatement(bodyNode));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import traverse from "../../../traversal";
|
||||
import * as t from "../../../types";
|
||||
|
||||
var visitor = {
|
||||
enter(node, parent, scope, state) {
|
||||
if (!this.isReferencedIdentifier()) return;
|
||||
var visitor = traverse.explode({
|
||||
ReferencedIdentifier(node, parent, scope, state) {
|
||||
if (t.isFor(parent) && parent.left === node) return;
|
||||
|
||||
var declared = state.letRefs[node.name];
|
||||
@@ -25,7 +25,7 @@ var visitor = {
|
||||
return t.logicalExpression("&&", assert, node);
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
export var metadata = {
|
||||
optional: true
|
||||
|
||||
@@ -33,3 +33,5 @@ export function BinaryExpression(node, parent, scope, file) {
|
||||
export function VariableDeclaration(node) {
|
||||
if (node._generated) this.skip();
|
||||
}
|
||||
|
||||
export { VariableDeclaration as FunctionDeclaration };
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import reduceRight from "lodash/collection/reduceRight";
|
||||
import * as messages from "../../../messages";
|
||||
import flatten from "lodash/array/flatten";
|
||||
import traverse from "../../../traversal";
|
||||
import * as util from "../../../util";
|
||||
import map from "lodash/collection/map";
|
||||
import * as t from "../../../types";
|
||||
@@ -16,62 +17,61 @@ function returnBlock(expr) {
|
||||
}
|
||||
|
||||
// looks for and replaces tail recursion calls
|
||||
var firstPass = {
|
||||
var firstPass = traverse.explode({
|
||||
enter(node, parent, scope, state) {
|
||||
if (this.isIfStatement()) {
|
||||
if (this.get("alternate").isReturnStatement()) {
|
||||
t.ensureBlock(node, "alternate");
|
||||
}
|
||||
|
||||
if (this.get("consequent").isReturnStatement()) {
|
||||
t.ensureBlock(node, "consequent");
|
||||
}
|
||||
} else if (this.isReturnStatement()) {
|
||||
this.skip();
|
||||
return state.subTransform(node.argument);
|
||||
} else if (t.isTryStatement(parent)) {
|
||||
if (t.isTryStatement(parent)) {
|
||||
if (node === parent.block) {
|
||||
this.skip();
|
||||
} else if (parent.finalizer && node !== parent.finalizer) {
|
||||
this.skip();
|
||||
}
|
||||
} else if (this.isFunction()) {
|
||||
this.skip();
|
||||
} else if (this.isVariableDeclaration()) {
|
||||
this.skip();
|
||||
state.vars.push(node);
|
||||
}
|
||||
},
|
||||
|
||||
ReturnStatement(node, parent, scope, state) {
|
||||
this.skip();
|
||||
return state.subTransform(node.argument);
|
||||
},
|
||||
|
||||
Function(node, parent, scope, state) {
|
||||
this.skip();
|
||||
},
|
||||
|
||||
VariableDeclaration(node, parent, scope, state) {
|
||||
this.skip();
|
||||
state.vars.push(node);
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
// hoists up function declarations, replaces `this` and `arguments` and marks
|
||||
// them as needed
|
||||
var secondPass = {
|
||||
enter(node, parent, scope, state) {
|
||||
if (this.isThisExpression()) {
|
||||
state.needsThis = true;
|
||||
return state.getThisId();
|
||||
} else if (this.isReferencedIdentifier({ name: "arguments" })) {
|
||||
state.needsArguments = true;
|
||||
return state.getArgumentsId();
|
||||
} else if (this.isFunction()) {
|
||||
this.skip();
|
||||
if (this.isFunctionDeclaration()) {
|
||||
node = t.variableDeclaration("var", [
|
||||
t.variableDeclarator(node.id, t.toExpression(node))
|
||||
]);
|
||||
node._blockHoist = 2;
|
||||
return node;
|
||||
}
|
||||
var secondPass = traverse.explode({
|
||||
ThisExpression(node, parent, scope, state) {
|
||||
state.needsThis = true;
|
||||
return state.getThisId();
|
||||
},
|
||||
|
||||
ReferencedIdentifier(node, parent, scope, state) {
|
||||
if (node.name !== "arguments") return;
|
||||
state.needsArguments = true;
|
||||
return state.getArgumentsId();
|
||||
},
|
||||
|
||||
Function(node, parent, scope, state) {
|
||||
this.skip();
|
||||
if (this.isFunctionDeclaration()) {
|
||||
node = t.variableDeclaration("var", [
|
||||
t.variableDeclarator(node.id, t.toExpression(node))
|
||||
]);
|
||||
node._blockHoist = 2;
|
||||
return node;
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
// optimizes recursion by removing `this` and `arguments` if they aren't used
|
||||
var thirdPass = {
|
||||
enter(node, parent, scope, state) {
|
||||
if (!this.isExpressionStatement()) return;
|
||||
|
||||
var thirdPass = traverse.explode({
|
||||
ExpressionStatement(node, parent, scope, state) {
|
||||
var expr = node.expression;
|
||||
if (!t.isAssignmentExpression(expr)) return;
|
||||
|
||||
@@ -83,7 +83,7 @@ var thirdPass = {
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
class TailCallTransformer {
|
||||
constructor(path, scope, file) {
|
||||
|
||||
@@ -1,4 +1,12 @@
|
||||
export default {
|
||||
"utility.removeDebugger": require("./utility/remove-debugger"),
|
||||
"utility.removeConsole": require("./utility/remove-console"),
|
||||
|
||||
"utility.inlineEnvironmentVariables": require("./utility/inline-environment-variables"),
|
||||
"utility.inlineExpressions": require("./utility/inline-expressions"),
|
||||
|
||||
"minification.deadCodeElimination": require("./minification/dead-code-elimination"),
|
||||
|
||||
_modules: require("./internal/modules"),
|
||||
|
||||
"es7.classProperties": require("./es7/class-properties"),
|
||||
@@ -108,12 +116,8 @@ export default {
|
||||
"es3.propertyLiterals": require("./es3/property-literals"),
|
||||
"es3.memberExpressionLiterals": require("./es3/member-expression-literals"),
|
||||
|
||||
"utility.removeDebugger": require("./utility/remove-debugger"),
|
||||
"utility.removeConsole": require("./utility/remove-console"),
|
||||
|
||||
"utility.inlineEnvironmentVariables": require("./utility/inline-environment-variables"),
|
||||
"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"),
|
||||
flow: require("./other/flow")
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
import groupBy from "lodash/collection/groupBy";
|
||||
import flatten from "lodash/array/flatten";
|
||||
import values from "lodash/object/values";
|
||||
import sortBy from "lodash/collection/sortBy";
|
||||
|
||||
// Priority:
|
||||
//
|
||||
@@ -18,14 +16,14 @@ export var BlockStatement = {
|
||||
}
|
||||
if (!hasChange) return;
|
||||
|
||||
var nodePriorities = groupBy(node.body, function (bodyNode) {
|
||||
node.body = sortBy(node.body, function(bodyNode){
|
||||
var priority = bodyNode && bodyNode._blockHoist;
|
||||
if (priority == null) priority = 1;
|
||||
if (priority === true) priority = 2;
|
||||
return priority;
|
||||
});
|
||||
|
||||
node.body = flatten(values(nodePriorities).reverse());
|
||||
// Higher priorities should move toward the top.
|
||||
return -1 * priority;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,9 @@ import { _ForOfStatementArray } from "../es6/for-of";
|
||||
import * as t from "../../../types";
|
||||
|
||||
export var shouldVisit = t.isForOfStatement;
|
||||
export var optional = true;
|
||||
export var metadata = {
|
||||
optional: true
|
||||
};
|
||||
|
||||
export function ForOfStatement(node, parent, scope, file) {
|
||||
if (this.get("right").isTypeGeneric("Array")) {
|
||||
|
||||
@@ -9,6 +9,6 @@ export var Program = {
|
||||
enter(ast) {
|
||||
regenerator.transform(ast);
|
||||
this.stop();
|
||||
return ast; // force a checkPath, this really needs to be optimised
|
||||
this.checkSelf();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -15,7 +15,7 @@ export default class Binding {
|
||||
* Description
|
||||
*/
|
||||
|
||||
setTypeAnnotation() {
|
||||
setTypeAnnotation() {
|
||||
var typeInfo = this.path.getTypeAnnotation();
|
||||
this.typeAnnotationInferred = typeInfo.inferred;
|
||||
this.typeAnnotation = typeInfo.annotation;
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
import * as t from "../types";
|
||||
|
||||
export default function (obj) {
|
||||
for (var type in obj) {
|
||||
var fns = obj[type];
|
||||
if (typeof fns === "function") {
|
||||
obj[type] = fns = { enter: fns };
|
||||
}
|
||||
|
||||
var aliases = t.FLIPPED_ALIAS_KEYS[type];
|
||||
if (aliases) {
|
||||
for (var i = 0; i < aliases.length; i++) {
|
||||
var alias = aliases[i];
|
||||
obj[alias] = obj[alias] || fns;
|
||||
}
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import TraversalContext from "./context";
|
||||
import explode from "./explode";
|
||||
import { explode, verify } from "./visitors";
|
||||
import * as messages from "../messages";
|
||||
import includes from "lodash/collection/includes";
|
||||
import * as t from "../types";
|
||||
@@ -14,7 +14,7 @@ export default function traverse(parent, opts, scope, state, parentPath) {
|
||||
}
|
||||
|
||||
if (!opts) opts = {};
|
||||
traverse.verify(opts);
|
||||
verify(opts);
|
||||
|
||||
// array of nodes
|
||||
if (Array.isArray(parent)) {
|
||||
@@ -26,42 +26,8 @@ export default function traverse(parent, opts, scope, state, parentPath) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Quickly iterate over some traversal options and validate them.
|
||||
*/
|
||||
|
||||
traverse.verify = function (opts) {
|
||||
if (opts._verified) return;
|
||||
|
||||
if (typeof opts === "function") {
|
||||
throw new Error(messages.get("traverseVerifyRootFunction"));
|
||||
}
|
||||
|
||||
if (!opts.enter) opts.enter = function () { };
|
||||
if (!opts.exit) opts.exit = function () { };
|
||||
if (!opts.shouldSkip) opts.shouldSkip = function () { return false; };
|
||||
|
||||
for (var key in opts) {
|
||||
// it's all good
|
||||
if (key === "blacklist") continue;
|
||||
|
||||
var opt = opts[key];
|
||||
|
||||
if (typeof opt === "function") {
|
||||
// it's all good, it's fine for this key to be a function
|
||||
if (key === "enter" || key === "exit" || key === "shouldSkip") continue;
|
||||
|
||||
throw new Error(messages.get("traverseVerifyVisitorFunction", key));
|
||||
} else if (typeof opt === "object") {
|
||||
for (var key2 in opt) {
|
||||
if (key2 === "enter" || key2 === "exit") continue;
|
||||
throw new Error(messages.get("traverseVerifyVisitorProperty", key, key2));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
opts._verified = true;
|
||||
};
|
||||
traverse.verify = verify;
|
||||
traverse.explode = explode;
|
||||
|
||||
traverse.node = function (node, opts, scope, state, parentPath) {
|
||||
var keys = t.VISITOR_KEYS[node.type];
|
||||
@@ -113,8 +79,6 @@ traverse.removeProperties = function (tree) {
|
||||
return tree;
|
||||
};
|
||||
|
||||
traverse.explode = explode;
|
||||
|
||||
function hasBlacklistedType(node, parent, scope, state) {
|
||||
if (node.type === state.type) {
|
||||
state.has = true;
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
import PathHoister from "./hoister";
|
||||
import * as virtualTypes from "./virtual-types";
|
||||
import isBoolean from "lodash/lang/isBoolean";
|
||||
import isNumber from "lodash/lang/isNumber";
|
||||
import isRegExp from "lodash/lang/isRegExp";
|
||||
import isString from "lodash/lang/isString";
|
||||
import codeFrame from "../../helpers/code-frame";
|
||||
import parse from "../../helpers/parse";
|
||||
import { explode } from "../visitors";
|
||||
import traverse from "../index";
|
||||
import includes from "lodash/collection/includes";
|
||||
import assign from "lodash/object/assign";
|
||||
@@ -10,33 +14,33 @@ import extend from "lodash/object/extend";
|
||||
import Scope from "../scope";
|
||||
import * as t from "../../types";
|
||||
|
||||
var hoistVariablesVisitor = {
|
||||
enter(node, parent, scope) {
|
||||
if (this.isFunction()) {
|
||||
return this.skip();
|
||||
}
|
||||
var hoistVariablesVisitor = explode({
|
||||
Function() {
|
||||
this.skip();
|
||||
},
|
||||
|
||||
VariableDeclaration(node, parent, scope) {
|
||||
if (node.kind !== "var") return;
|
||||
|
||||
if (this.isVariableDeclaration() && node.kind === "var") {
|
||||
var bindings = this.getBindingIdentifiers();
|
||||
for (var key in bindings) {
|
||||
scope.push({ id: bindings[key] });
|
||||
}
|
||||
|
||||
var exprs = [];
|
||||
|
||||
for (var i = 0; i < node.declarations.length; i++) {
|
||||
var declar = node.declarations[i];
|
||||
if (declar.init) {
|
||||
exprs.push(t.expressionStatement(
|
||||
t.assignmentExpression("=", declar.id, declar.init)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
return exprs;
|
||||
for (var key in bindings) {
|
||||
scope.push({ id: bindings[key] });
|
||||
}
|
||||
|
||||
var exprs = [];
|
||||
|
||||
for (var i = 0; i < node.declarations.length; i++) {
|
||||
var declar = node.declarations[i];
|
||||
if (declar.init) {
|
||||
exprs.push(t.expressionStatement(
|
||||
t.assignmentExpression("=", declar.id, declar.init)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
return exprs;
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
export default class TraversalPath {
|
||||
constructor(parent, container) {
|
||||
@@ -87,6 +91,22 @@ export default class TraversalPath {
|
||||
return ourScope;
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
*/
|
||||
|
||||
getAncestry() {
|
||||
var ancestry = [];
|
||||
|
||||
var path = this.parentPath;
|
||||
while (path) {
|
||||
ancestry.push(path.node);
|
||||
path = path.parentPath;
|
||||
}
|
||||
|
||||
return ancestry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
*/
|
||||
@@ -116,7 +136,7 @@ export default class TraversalPath {
|
||||
} else if (this.isStatementOrBlock()) {
|
||||
if (this.node) nodes.push(this.node);
|
||||
this.container[this.key] = t.blockStatement(nodes);
|
||||
this.checkPaths(this);
|
||||
this.checkSelf();
|
||||
} 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?");
|
||||
}
|
||||
@@ -214,7 +234,7 @@ export default class TraversalPath {
|
||||
} else if (this.isStatementOrBlock()) {
|
||||
if (this.node) nodes.unshift(this.node);
|
||||
this.container[this.key] = t.blockStatement(nodes);
|
||||
this.checkPaths(this);
|
||||
this.checkSelf();
|
||||
} 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?");
|
||||
}
|
||||
@@ -476,7 +496,29 @@ export default class TraversalPath {
|
||||
* Description
|
||||
*/
|
||||
|
||||
replaceWith(replacement, arraysAllowed) {
|
||||
replaceWithSourceString(replacement) {
|
||||
try {
|
||||
replacement = `(${replacement})`;
|
||||
replacement = parse(replacement);
|
||||
} 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.program.body[0].expression;
|
||||
traverse.removeProperties(replacement);
|
||||
return this.replaceWith(replacement);
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
*/
|
||||
|
||||
replaceWith(replacement, whateverAllowed) {
|
||||
if (this.removed) {
|
||||
throw new Error("You can't replace this node, we've already removed it");
|
||||
}
|
||||
@@ -485,14 +527,38 @@ export default class TraversalPath {
|
||||
throw new Error("You passed `path.replaceWith()` a falsy node, use `path.remove()` instead");
|
||||
}
|
||||
|
||||
if (this.node === replacement) {
|
||||
return this.checkSelf();
|
||||
}
|
||||
|
||||
// normalise inserting an entire AST
|
||||
if (t.isProgram(replacement)) {
|
||||
replacement = replacement.body;
|
||||
whateverAllowed = true;
|
||||
}
|
||||
|
||||
if (Array.isArray(replacement)) {
|
||||
if (arraysAllowed) {
|
||||
if (whateverAllowed) {
|
||||
return this.replaceWithMultiple(replacement);
|
||||
} else {
|
||||
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)) {
|
||||
return this.replaceExpressionWithStatements([replacement]);
|
||||
}
|
||||
@@ -507,6 +573,14 @@ export default class TraversalPath {
|
||||
// potentially create new scope
|
||||
this.setScope();
|
||||
|
||||
this.checkSelf();
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
*/
|
||||
|
||||
checkSelf() {
|
||||
this.checkPaths(this);
|
||||
}
|
||||
|
||||
@@ -606,12 +680,21 @@ export default class TraversalPath {
|
||||
if (!node) return;
|
||||
|
||||
var opts = this.opts;
|
||||
var fn = opts[key] || opts;
|
||||
if (opts[node.type]) fn = opts[node.type][key] || fn;
|
||||
var fns = [].concat(opts[key]);
|
||||
|
||||
// call the function with the params (node, parent, scope, state)
|
||||
var replacement = fn.call(this, node, this.parent, this.scope, this.state);
|
||||
if (replacement) this.replaceWith(replacement, true);
|
||||
if (opts[node.type]) {
|
||||
fns = fns.concat(opts[node.type][key]);
|
||||
}
|
||||
|
||||
for (var fn of (fns: Array)) {
|
||||
if (!fn) continue;
|
||||
|
||||
// call the function with the params (node, parent, scope, state)
|
||||
var replacement = fn.call(this, node, this.parent, this.scope, this.state);
|
||||
if (replacement) this.replaceWith(replacement, true);
|
||||
|
||||
if (this.shouldStop) break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -873,46 +956,6 @@ export default class TraversalPath {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
*/
|
||||
|
||||
isScope(): boolean {
|
||||
return t.isScope(this.node, this.parent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
*/
|
||||
|
||||
isReferencedIdentifier(opts): boolean {
|
||||
return t.isReferencedIdentifier(this.node, this.parent, opts);
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
*/
|
||||
|
||||
isReferenced(): boolean {
|
||||
return t.isReferenced(this.node, this.parent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
*/
|
||||
|
||||
isBlockScoped(): boolean {
|
||||
return t.isBlockScoped(this.node);
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
*/
|
||||
|
||||
isVar(): boolean {
|
||||
return t.isVar(this.node);
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
*/
|
||||
@@ -1031,8 +1074,15 @@ export default class TraversalPath {
|
||||
assign(TraversalPath.prototype, require("./evaluation"));
|
||||
assign(TraversalPath.prototype, require("./conversion"));
|
||||
|
||||
for (var i = 0; i < t.TYPES.length; i++) {
|
||||
let type = t.TYPES[i];
|
||||
for (let type in virtualTypes) {
|
||||
if (type[0] === "_") continue;
|
||||
|
||||
TraversalPath.prototype[`is${type}`] = function (opts) {
|
||||
return virtualTypes[type].checkPath(this, opts);
|
||||
};
|
||||
}
|
||||
|
||||
for (let type of (t.TYPES: Array)) {
|
||||
let typeKey = `is${type}`;
|
||||
TraversalPath.prototype[typeKey] = function (opts) {
|
||||
return t[typeKey](this.node, opts);
|
||||
|
||||
34
src/babel/traversal/path/virtual-types.js
Normal file
34
src/babel/traversal/path/virtual-types.js
Normal file
@@ -0,0 +1,34 @@
|
||||
import * as t from "../../types";
|
||||
|
||||
export var ReferencedIdentifier = {
|
||||
type: "Identifier",
|
||||
checkPath(path, opts) {
|
||||
return t.isReferencedIdentifier(path.node, path.parent, opts);
|
||||
}
|
||||
};
|
||||
|
||||
export var Scope = {
|
||||
type: "Scopable",
|
||||
checkPath(path) {
|
||||
return t.isScope(path.node, path.parent);
|
||||
}
|
||||
};
|
||||
|
||||
export var Referenced = {
|
||||
checkPath(path) {
|
||||
return t.isReferenced(path.node, path.parent);
|
||||
}
|
||||
};
|
||||
|
||||
export var BlockScoped = {
|
||||
checkPath(path) {
|
||||
return t.isBlockScoped(path.node);
|
||||
}
|
||||
};
|
||||
|
||||
export var Var = {
|
||||
type: "VariableDeclaration",
|
||||
checkPath(path) {
|
||||
return t.isVar(path.node);
|
||||
}
|
||||
};
|
||||
@@ -1,5 +1,5 @@
|
||||
import includes from "lodash/collection/includes";
|
||||
import explode from "./explode";
|
||||
import { explode } from "./visitors";
|
||||
import traverse from "./index";
|
||||
import defaults from "lodash/object/defaults";
|
||||
import * as messages from "../messages";
|
||||
@@ -38,47 +38,72 @@ var functionVariableVisitor = {
|
||||
}
|
||||
};
|
||||
|
||||
var programReferenceVisitor = {
|
||||
enter(node, parent, scope, state) {
|
||||
if (t.isReferencedIdentifier(node, parent)) {
|
||||
var bindingInfo = scope.getBinding(node.name);
|
||||
if (bindingInfo) {
|
||||
bindingInfo.reference();
|
||||
} else {
|
||||
state.addGlobal(node);
|
||||
}
|
||||
} else if (t.isLabeledStatement(node)) {
|
||||
var programReferenceVisitor = explode({
|
||||
ReferencedIdentifier(node, parent, scope, state) {
|
||||
var bindingInfo = scope.getBinding(node.name);
|
||||
if (bindingInfo) {
|
||||
bindingInfo.reference();
|
||||
} else {
|
||||
state.addGlobal(node);
|
||||
} else if (t.isAssignmentExpression(node)) {
|
||||
scope.registerConstantViolation(this.get("left"), this.get("right"));
|
||||
} else if (t.isUpdateExpression(node)) {
|
||||
scope.registerConstantViolation(this.get("argument"), null);
|
||||
} else if (t.isUnaryExpression(node) && node.operator === "delete") {
|
||||
scope.registerConstantViolation(this.get("left"), null);
|
||||
}
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
ExportDeclaration(node, parent, scope, state) {
|
||||
var declar = node.declaration;
|
||||
if (t.isClassDeclaration(declar) || t.isFunctionDeclaration(declar)) {
|
||||
scope.getBinding(declar.id.name).reference();
|
||||
} else if (t.isVariableDeclaration(declar)) {
|
||||
for (var decl of (declar.declarations: Array)) {
|
||||
scope.getBinding(decl.id.name).reference();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
LabeledStatement(node, parent, scope, state) {
|
||||
state.addGlobal(node);
|
||||
},
|
||||
|
||||
AssignmentExpression(node, parent, scope, state) {
|
||||
scope.registerConstantViolation(this.get("left"), this.get("right"));
|
||||
},
|
||||
|
||||
UpdateExpression(node, parent, scope, state) {
|
||||
scope.registerConstantViolation(this.get("argument"), null);
|
||||
},
|
||||
|
||||
UnaryExpression(node, parent, scope, state) {
|
||||
if (node.operator === "delete") scope.registerConstantViolation(this.get("left"), null);
|
||||
}
|
||||
});
|
||||
|
||||
var blockVariableVisitor = explode({
|
||||
Scope() {
|
||||
this.skip();
|
||||
},
|
||||
|
||||
var blockVariableVisitor = {
|
||||
enter(node, parent, scope, state) {
|
||||
if (this.isFunctionDeclaration() || this.isBlockScoped()) {
|
||||
state.registerDeclaration(this);
|
||||
}
|
||||
if (this.isScope()) {
|
||||
this.skip();
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
var renameVisitor = explode({
|
||||
Identifier(node, parent, scope, state) {
|
||||
if (this.isReferenced() && node.name === state.oldName) {
|
||||
if (this.parentPath.isProperty() && this.key === "key" && parent.shorthand) {
|
||||
parent.shorthand = false;
|
||||
parent.value = t.identifier(state.newName);
|
||||
} else {
|
||||
node.name = state.newName;
|
||||
ReferencedIdentifier(node, parent, scope, state) {
|
||||
if (node.name !== state.oldName) return;
|
||||
|
||||
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.value = value;
|
||||
parent.key = t.identifier(state.oldName);
|
||||
} else {
|
||||
node.name = state.newName;
|
||||
}
|
||||
},
|
||||
|
||||
@@ -237,12 +262,14 @@ export default class Scope {
|
||||
|
||||
var add = function (node) {
|
||||
if (t.isModuleDeclaration(node)) {
|
||||
if (node.specifiers && node.specifiers.length) {
|
||||
if (node.source) {
|
||||
add(node.source);
|
||||
} else if (node.specifiers && node.specifiers.length) {
|
||||
for (var i = 0; i < node.specifiers.length; i++) {
|
||||
add(node.specifiers[i]);
|
||||
}
|
||||
} else {
|
||||
add(node.source);
|
||||
} else if (node.declaration) {
|
||||
add(node.declaration);
|
||||
}
|
||||
} else if (t.isModuleSpecifier(node)) {
|
||||
add(node.local);
|
||||
|
||||
166
src/babel/traversal/visitors.js
Normal file
166
src/babel/traversal/visitors.js
Normal file
@@ -0,0 +1,166 @@
|
||||
import * as virtualTypes from "./path/virtual-types";
|
||||
import * as messages from "../messages";
|
||||
import * as t from "../types";
|
||||
import esquery from "esquery";
|
||||
|
||||
export function explode(visitor, mergeConflicts) {
|
||||
// make sure there's no __esModule type since this is because we're using loose mode
|
||||
// and it sets __esModule to be enumerable on all modules :(
|
||||
delete visitor.__esModule;
|
||||
|
||||
if (visitor.queries) {
|
||||
ensureEntranceObjects(visitor.queries);
|
||||
addQueries(visitor);
|
||||
delete visitor.queries;
|
||||
}
|
||||
|
||||
// ensure visitors are objects
|
||||
ensureEntranceObjects(visitor);
|
||||
|
||||
// add type wrappers
|
||||
for (let nodeType in visitor) {
|
||||
if (shouldIgnoreKey(nodeType)) continue;
|
||||
|
||||
var wrapper = virtualTypes[nodeType];
|
||||
if (!wrapper) continue;
|
||||
|
||||
// wrap all the functions
|
||||
var fns = visitor[nodeType];
|
||||
for (var type in fns) {
|
||||
fns[type] = wrapCheck(wrapper, fns[type]);
|
||||
}
|
||||
|
||||
// clear it from the visitor
|
||||
delete visitor[nodeType];
|
||||
|
||||
if (wrapper.type) {
|
||||
// merge the visitor if necessary or just put it back in
|
||||
if (visitor[wrapper.type]) {
|
||||
merge(visitor[wrapper.type], fns);
|
||||
} else {
|
||||
visitor[wrapper.type] = fns;
|
||||
}
|
||||
} else {
|
||||
merge(visitor, fns);
|
||||
}
|
||||
}
|
||||
|
||||
// add aliases
|
||||
for (let nodeType in visitor) {
|
||||
if (shouldIgnoreKey(nodeType)) continue;
|
||||
|
||||
var fns = visitor[nodeType];
|
||||
|
||||
var aliases = t.FLIPPED_ALIAS_KEYS[nodeType];
|
||||
if (!aliases) continue;
|
||||
|
||||
// clear it form the visitor
|
||||
delete visitor[nodeType];
|
||||
|
||||
for (var alias of (aliases: Array)) {
|
||||
var existing = visitor[alias];
|
||||
if (existing) {
|
||||
if (mergeConflicts) {
|
||||
merge(existing, fns);
|
||||
}
|
||||
} else {
|
||||
visitor[alias] = fns;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return visitor;
|
||||
}
|
||||
|
||||
export function verify(visitor) {
|
||||
if (visitor._verified) return;
|
||||
|
||||
if (typeof visitor === "function") {
|
||||
throw new Error(messages.get("traverseVerifyRootFunction"));
|
||||
}
|
||||
|
||||
if (!visitor.enter) visitor.enter = function () { };
|
||||
if (!visitor.exit) visitor.exit = function () { };
|
||||
if (!visitor.shouldSkip) visitor.shouldSkip = function () { return false; };
|
||||
|
||||
for (var nodeType in visitor) {
|
||||
if (shouldIgnoreKey(nodeType)) continue;
|
||||
|
||||
if (t.TYPES.indexOf(nodeType) < 0) {
|
||||
throw new Error(messages.get("traverseVerifyNodeType", nodeType));
|
||||
}
|
||||
|
||||
var visitors = visitor[nodeType];
|
||||
|
||||
if (typeof visitors === "function") {
|
||||
throw new Error(messages.get("traverseVerifyVisitorFunction", nodeType));
|
||||
} else if (typeof visitors === "object") {
|
||||
for (var visitorKey in visitors) {
|
||||
if (visitorKey === "enter" || visitorKey === "exit") continue;
|
||||
throw new Error(messages.get("traverseVerifyVisitorProperty", nodeType, visitorKey));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
visitor._verified = true;
|
||||
}
|
||||
|
||||
function ensureEntranceObjects(obj) {
|
||||
for (let key in obj) {
|
||||
if (shouldIgnoreKey(key)) continue;
|
||||
|
||||
var fns = obj[key];
|
||||
if (typeof fns === "function") {
|
||||
obj[key] = { enter: fns };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function addQueries(visitor) {
|
||||
for (var selector in visitor.queries) {
|
||||
var fns = visitor.queries[selector];
|
||||
addSelector(visitor, selector, fns);
|
||||
}
|
||||
}
|
||||
|
||||
function addSelector(visitor, selector, fns) {
|
||||
selector = esquery.parse(selector);
|
||||
|
||||
for (var key in fns) {
|
||||
let fn = fns[key];
|
||||
fns[key] = function (node) {
|
||||
if (esquery.matches(node, selector, this.getAncestry())) {
|
||||
return fn.apply(this, arguments);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
merge(visitor, fns);
|
||||
}
|
||||
|
||||
function wrapCheck(wrapper, fn) {
|
||||
return function () {
|
||||
if (wrapper.checkPath(this)) {
|
||||
return fn.apply(this, arguments);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function shouldIgnoreKey(key) {
|
||||
// internal/hidden key
|
||||
if (key[0] === "_") return true;
|
||||
|
||||
// ignore function keys
|
||||
if (key === "enter" || key === "exit" || key === "shouldSkip") return true;
|
||||
|
||||
// ignore other options
|
||||
if (key === "blacklist" || key === "noScope") return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function merge(dest, src) {
|
||||
for (var key in src) {
|
||||
dest[key] = (dest[key] || []).concat(src[key]);
|
||||
}
|
||||
}
|
||||
@@ -155,7 +155,7 @@ export function template(name: string, nodes?: Array<Object>, keepExpression?: b
|
||||
}
|
||||
|
||||
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);
|
||||
return ast;
|
||||
}
|
||||
|
||||
@@ -18,6 +18,77 @@ suite("api", function () {
|
||||
assert.ok(!result.ast);
|
||||
});
|
||||
|
||||
suite("getModuleId() {} option", function () {
|
||||
// As of this commit, `getModuleId` is the only option that isn't JSON
|
||||
// compatible which is why it's not inside /test/core/fixtures/transformation
|
||||
|
||||
function getModuleNameTest(moduleFormat, expected) {
|
||||
var result = transform("foo('bar');", {
|
||||
filename: "foo/bar/index",
|
||||
modules: moduleFormat,
|
||||
moduleIds: true,
|
||||
getModuleId: function (name) {
|
||||
return name.replace(/\/index$/, "");
|
||||
}
|
||||
});
|
||||
|
||||
assert.equal(result.code, expected);
|
||||
}
|
||||
|
||||
test("{ modules: \"amd\" }", function () {
|
||||
var expected = [
|
||||
"define('foo/bar', ['exports'], function (exports) {",
|
||||
" 'use strict';",
|
||||
"",
|
||||
" foo('bar');",
|
||||
"});"
|
||||
].join("\n");
|
||||
|
||||
getModuleNameTest("amd", expected);
|
||||
});
|
||||
|
||||
test("{ modules: \"umd\" }", function () {
|
||||
var expected = [
|
||||
"(function (global, factory) {",
|
||||
" if (typeof define === 'function' && define.amd) {",
|
||||
" define('foo/bar', ['exports'], factory);",
|
||||
" } else if (typeof exports !== 'undefined') {",
|
||||
" factory(exports);",
|
||||
" } else {",
|
||||
" var mod = {",
|
||||
" exports: {}",
|
||||
" };",
|
||||
" factory(mod.exports);",
|
||||
" global.fooBar = mod.exports;",
|
||||
" }",
|
||||
"})(this, function (exports) {",
|
||||
" 'use strict';",
|
||||
"",
|
||||
" foo('bar');",
|
||||
"});",
|
||||
].join("\n");
|
||||
|
||||
getModuleNameTest("umd", expected);
|
||||
});
|
||||
|
||||
test("{ modules: \"system\" }", function () {
|
||||
var expected = [
|
||||
"System.register('foo/bar', [], function (_export) {",
|
||||
" return {",
|
||||
" setters: [],",
|
||||
" execute: function () {",
|
||||
" 'use strict';",
|
||||
"",
|
||||
" foo('bar');",
|
||||
" }",
|
||||
" };",
|
||||
"});",
|
||||
].join("\n");
|
||||
|
||||
getModuleNameTest("system", expected);
|
||||
});
|
||||
});
|
||||
|
||||
test("addHelper unknown", function () {
|
||||
var file = new File({}, transform.pipeline);
|
||||
assert.throws(function () {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"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() {
|
||||
_classCallCheck(this, Test);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"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() {
|
||||
_classCallCheck(this, Test);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"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() {
|
||||
_classCallCheck(this, Test);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"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() {
|
||||
_classCallCheck(this, Test);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class Test {
|
||||
constructor() {
|
||||
arr.map(x => x * x);
|
||||
arr.map(x => x * x);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
obj["x"] = 2;
|
||||
|
||||
test.catch;
|
||||
test.catch["foo"];
|
||||
test.catch.foo;
|
||||
test["catch"];
|
||||
test["catch"]["foo"];
|
||||
test["catch"].foo;
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
"use strict";
|
||||
|
||||
obj.x = 2;
|
||||
|
||||
test["catch"];
|
||||
test["catch"].foo;
|
||||
test["catch"];
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"use strict";
|
||||
|
||||
var obj = {
|
||||
test: "foob",
|
||||
"test": "foob",
|
||||
"!@#$": "foob",
|
||||
"33rd": "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);
|
||||
@@ -5,15 +5,15 @@ Object.defineProperty(exports, "__esModule", {
|
||||
});
|
||||
exports.nextOdd = nextOdd;
|
||||
|
||||
var _isEven = require("./evens");
|
||||
var _evens = require("./evens");
|
||||
|
||||
function nextOdd(n) {
|
||||
return _isEven.isEven(n) ? n + 1 : n + 2;
|
||||
return _evens.isEven(n) ? n + 1 : n + 2;
|
||||
}
|
||||
|
||||
var isOdd = (function (isEven) {
|
||||
return function (n) {
|
||||
return !isEven(n);
|
||||
};
|
||||
})(_isEven.isEven);
|
||||
exports.isOdd = isOdd;
|
||||
})(_evens.isEven);
|
||||
exports.isOdd = isOdd;
|
||||
@@ -4,7 +4,7 @@ var _foo = require("foo");
|
||||
|
||||
var _foo2 = babelHelpers.interopRequireDefault(_foo);
|
||||
|
||||
var _foo22 = babelHelpers.interopRequireDefault(_foo);
|
||||
var _foo3 = babelHelpers.interopRequireDefault(_foo);
|
||||
|
||||
_foo2["default"];
|
||||
_foo22["default"];
|
||||
_foo3["default"];
|
||||
@@ -1,5 +1,5 @@
|
||||
"use strict";
|
||||
|
||||
var _import = require("foo");
|
||||
var _foo = require("foo");
|
||||
|
||||
var foo = babelHelpers.interopRequireWildcard(_import);
|
||||
var foo = babelHelpers.interopRequireWildcard(_foo);
|
||||
@@ -1,8 +1,8 @@
|
||||
"use strict";
|
||||
|
||||
var _foo$xyz = require("foo");
|
||||
var _foo = require("foo");
|
||||
|
||||
var _foo$xyz2 = babelHelpers.interopRequireDefault(_foo$xyz);
|
||||
var _foo2 = babelHelpers.interopRequireDefault(_foo);
|
||||
|
||||
_foo$xyz2["default"];
|
||||
_foo$xyz.baz;
|
||||
_foo2["default"];
|
||||
_foo.baz;
|
||||
@@ -1,10 +1,10 @@
|
||||
"use strict";
|
||||
|
||||
var _bar = require("foo");
|
||||
var _foo = require("foo");
|
||||
|
||||
_bar.bar;
|
||||
_bar.bar2;
|
||||
_bar.baz;
|
||||
_bar.bar;
|
||||
_bar.bar;
|
||||
_bar.xyz;
|
||||
_foo.bar;
|
||||
_foo.bar2;
|
||||
_foo.baz;
|
||||
_foo.bar;
|
||||
_foo.bar;
|
||||
_foo.xyz;
|
||||
@@ -10,22 +10,22 @@ require("foo-bar");
|
||||
|
||||
require("./directory/foo-bar");
|
||||
|
||||
var _foo = require("foo2");
|
||||
var _foo2 = require("foo2");
|
||||
|
||||
var _foo2 = babelHelpers.interopRequireDefault(_foo);
|
||||
var _foo22 = babelHelpers.interopRequireDefault(_foo2);
|
||||
|
||||
var _import = require("foo3");
|
||||
var _foo3 = require("foo3");
|
||||
|
||||
var foo2 = babelHelpers.interopRequireWildcard(_import);
|
||||
var foo2 = babelHelpers.interopRequireWildcard(_foo3);
|
||||
|
||||
var _bar = require("foo4");
|
||||
var _foo4 = require("foo4");
|
||||
|
||||
var _bar2 = require("foo5");
|
||||
var _foo5 = require("foo5");
|
||||
|
||||
exports.test = test;
|
||||
var test = 5;
|
||||
|
||||
exports.test = test;
|
||||
_bar.bar;
|
||||
_bar2.foo;
|
||||
_foo2["default"];
|
||||
_foo4.bar;
|
||||
_foo5.foo;
|
||||
_foo22["default"];
|
||||
@@ -1,6 +1,6 @@
|
||||
"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 _class = function _default() {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"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,
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
System.register([], function (_export) {
|
||||
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);
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function foo() {}
|
||||
|
||||
return {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
System.register([], function (_export) {
|
||||
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);
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function foo7() {}
|
||||
|
||||
return {
|
||||
|
||||
@@ -2,4 +2,4 @@
|
||||
|
||||
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";
|
||||
|
||||
var _foo;
|
||||
|
||||
var foo = (_foo = {}, _foo[Symbol.iterator] = "foobar", _foo);
|
||||
var foo = babelHelpers.defineProperty({}, Symbol.iterator, "foobar");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
"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());
|
||||
@@ -1,5 +1,5 @@
|
||||
"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());
|
||||
@@ -4,8 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
var _foo2 = require("bar");
|
||||
var _bar = require("bar");
|
||||
|
||||
var _foo3 = babelHelpers.interopRequireDefault(_foo2);
|
||||
var _bar2 = babelHelpers.interopRequireDefault(_bar);
|
||||
|
||||
exports.foo = _foo3["default"];
|
||||
exports.foo = _bar2["default"];
|
||||
@@ -4,8 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
var _import = require("bar");
|
||||
var _bar = require("bar");
|
||||
|
||||
var _foo = babelHelpers.interopRequireWildcard(_import);
|
||||
var _foo = babelHelpers.interopRequireWildcard(_bar);
|
||||
|
||||
exports.foo = _foo;
|
||||
exports.foo = _foo;
|
||||
@@ -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"
|
||||
};
|
||||
@@ -1,7 +1,7 @@
|
||||
"use strict";
|
||||
|
||||
var _toString = require("foo");
|
||||
var _foo = require("foo");
|
||||
|
||||
var _toString2 = babelHelpers.interopRequireDefault(_toString);
|
||||
var _foo2 = babelHelpers.interopRequireDefault(_foo);
|
||||
|
||||
_toString2["default"];
|
||||
_foo2["default"];
|
||||
@@ -17,11 +17,11 @@ _Object$defineProperty(exports, "__esModule", {
|
||||
exports.giveWord = giveWord;
|
||||
var marked0$0 = [giveWord].map(_regeneratorRuntime.mark);
|
||||
|
||||
var _foo = require("someModule");
|
||||
var _someModule = require("someModule");
|
||||
|
||||
var _foo2 = _interopRequireDefault(_foo);
|
||||
var _someModule2 = _interopRequireDefault(_someModule);
|
||||
|
||||
var bar = _interopRequireWildcard(_foo);
|
||||
var bar = _interopRequireWildcard(_someModule);
|
||||
|
||||
var myWord = _Symbol("abc");
|
||||
exports.myWord = myWord;
|
||||
@@ -40,5 +40,5 @@ function giveWord() {
|
||||
}, marked0$0[0], this);
|
||||
}
|
||||
|
||||
_foo2["default"];
|
||||
bar;
|
||||
_someModule2["default"];
|
||||
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);
|
||||
}
|
||||
@@ -4,9 +4,9 @@ Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
var _last2 = require("lodash/array/last");
|
||||
var _lodashArrayLast = require("lodash/array/last");
|
||||
|
||||
var _last3 = babelHelpers.interopRequireDefault(_last2);
|
||||
var _lodashArrayLast2 = babelHelpers.interopRequireDefault(_lodashArrayLast);
|
||||
|
||||
var Container = (function () {
|
||||
function Container() {
|
||||
@@ -20,11 +20,11 @@ var Container = (function () {
|
||||
return;
|
||||
}
|
||||
|
||||
return _last3["default"](this.tokens.get(key));
|
||||
return _lodashArrayLast2["default"](this.tokens.get(key));
|
||||
}
|
||||
}]);
|
||||
return Container;
|
||||
})();
|
||||
|
||||
exports["default"] = Container;
|
||||
module.exports = exports["default"];
|
||||
module.exports = exports["default"];
|
||||
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
var _getForm2 = require("./store");
|
||||
var _store = require("./store");
|
||||
|
||||
var Login = (function (_React$Component) {
|
||||
function Login() {
|
||||
@@ -19,11 +19,11 @@ var Login = (function (_React$Component) {
|
||||
babelHelpers.createClass(Login, [{
|
||||
key: "getForm",
|
||||
value: function getForm() {
|
||||
return _getForm2.getForm().toJS();
|
||||
return _store.getForm().toJS();
|
||||
}
|
||||
}]);
|
||||
return Login;
|
||||
})(React.Component);
|
||||
|
||||
exports["default"] = Login;
|
||||
module.exports = exports["default"];
|
||||
module.exports = exports["default"];
|
||||
@@ -1,6 +1,6 @@
|
||||
"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;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
"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);
|
||||
@@ -1,10 +1,10 @@
|
||||
"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) {
|
||||
function Foo() {
|
||||
@@ -18,4 +18,4 @@ var Foo = (function (_Bar) {
|
||||
_inherits(Foo, _Bar);
|
||||
|
||||
return Foo;
|
||||
})(Bar);
|
||||
})(Bar);
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user