Compare commits

...

66 Commits

Author SHA1 Message Date
Sebastian McKenzie
53f0f0302b v5.2.16 2015-05-06 16:44:28 +01:00
Sebastian McKenzie
c25a5d2480 add 5.2.16 changelog 2015-05-06 16:43:21 +01:00
Sebastian McKenzie
fc8540d88a inherit destructuring param replacement ref from original param - fixes #1461 2015-05-06 16:29:54 +01:00
Sebastian McKenzie
31a4195c81 fix incorrect extensions variable reference - fixes #1460 2015-05-06 16:23:15 +01:00
Sebastian McKenzie
bf0e4ede00 pass correct function scope to nameMethod.property when naming class methods - fixes #1456 2015-05-06 16:03:15 +01:00
Sebastian McKenzie
3757bc6b9a reverse method decorators - fixes #1457 2015-05-06 15:57:21 +01:00
Sebastian McKenzie
2e01f220da Merge branch 'master' of github.com:babel/babel 2015-05-06 15:44:05 +01:00
Sebastian McKenzie
8ae4e1fdf2 add --harmony_rest_parameters flag to babel-node - fixes #1446 2015-05-06 15:43:51 +01:00
Sebastian McKenzie
f6219ec15a Merge pull request #1455 from monsanto/fix-async-constructor
Disallow async constructors
2015-05-06 15:12:12 +01:00
Christopher Monsanto
6a82eb5a5c disallow async constructors -- fixes #1454 2015-05-06 02:50:11 -04:00
Sebastian McKenzie
a241300ff1 force plugins to be ran at all times - fixes #1450 2015-05-06 01:14:17 +01:00
Sebastian McKenzie
d5548a6ff9 5.2.15 2015-05-05 15:41:57 +01:00
Sebastian McKenzie
ba6cb112c3 v5.2.15 2015-05-05 15:41:00 +01:00
Sebastian McKenzie
8f1bb84930 add 5.2.15 changelog 2015-05-05 15:39:05 +01:00
Sebastian McKenzie
235726eee6 remove unnecessary descriptor.initializer check 2015-05-05 15:38:17 +01:00
Sebastian McKenzie
08183ef490 don't add descriptor if we can't find it 2015-05-05 15:37:24 +01:00
Sebastian McKenzie
dc6fc3b30a fix browser-polyfill.js post-make publish purging 2015-05-05 15:37:11 +01:00
Sebastian McKenzie
76f2eb5684 5.2.14 2015-05-05 15:14:59 +01:00
Sebastian McKenzie
4f33687957 v5.2.14 2015-05-05 15:12:19 +01:00
Sebastian McKenzie
74f37fe0a3 expose unminified and minified builds of dist scripts - fixes #1444 2015-05-05 15:11:00 +01:00
Sebastian McKenzie
cc5e4bce52 fix object/property decorator interop 2015-05-05 14:42:41 +01:00
Sebastian McKenzie
f441a7cae8 don't do pretty variable declaration formatting if retainLines is enabled 2015-05-05 14:04:51 +01:00
Sebastian McKenzie
fc2be81c43 expose retainLines option to CLI 2015-05-05 14:04:36 +01:00
Sebastian McKenzie
1277a8f67f 5.2.13 2015-05-05 08:58:35 +01:00
Sebastian McKenzie
86c6d4e769 v5.2.13 2015-05-05 08:57:41 +01:00
Sebastian McKenzie
bf2d527cfe upgrade esquery 2015-05-05 08:56:58 +01:00
Sebastian McKenzie
6b59ea8eac add 5.2.13 changelog 2015-05-05 08:56:28 +01:00
Sebastian McKenzie
72e3cb9243 trigger a reference for export declarations 2015-05-05 08:54:51 +01:00
Sebastian McKenzie
5e5ede6058 move down _modules transformer 2015-05-05 08:54:38 +01:00
Sebastian McKenzie
d25944ea1f move utility transformers to top - fixes #1440 2015-05-05 08:39:46 +01:00
Sebastian McKenzie
fce2aa8fa3 add support for esquery 2015-05-05 03:21:31 +01:00
Sebastian McKenzie
0112c63779 consolidate the concept of "virtual types" 2015-05-05 02:33:49 +01:00
Sebastian McKenzie
6a4e93bf0f make visitor validation more anal, add node type wrappers, add mixin support to visitor explosion, allow visitor entrance/exit to provide an array of callbacks to use rather than limiting it to a single callback 2015-05-05 01:44:01 +01:00
Sebastian McKenzie
4328e920d2 5.2.12 2015-05-05 00:15:48 +01:00
Sebastian McKenzie
bbbf0a895d v5.2.12 2015-05-05 00:13:57 +01:00
Sebastian McKenzie
3289b33806 remove no self node replacement error 2015-05-05 00:13:07 +01:00
Sebastian McKenzie
f4b9faa6b3 clean up module declaration based UID generation - fixes #1437 2015-05-04 22:36:18 +01:00
Sebastian McKenzie
239b77816f 5.2.11 2015-05-04 22:33:26 +01:00
Sebastian McKenzie
8565e2b4e5 v5.2.11 2015-05-04 22:32:28 +01:00
Sebastian McKenzie
4317a46a3e add 5.2.11 changelog 2015-05-04 22:31:44 +01:00
Sebastian McKenzie
81ca29adc3 5.2.10 2015-05-04 22:31:38 +01:00
Sebastian McKenzie
c1a6ff7f44 rename getModuleName option to getModuleId 2015-05-04 22:31:34 +01:00
Sebastian McKenzie
7e6e5d4746 v5.2.10 2015-05-04 22:23:39 +01:00
Sebastian McKenzie
12d650e195 checkSelf() for destructuring catch clauses 2015-05-04 22:22:39 +01:00
Sebastian McKenzie
8fb58492df fix default specifiers not taking into consideration sourced imports 2015-05-04 22:20:52 +01:00
Sebastian McKenzie
2c0c2f12df avoid trying to replace a node with itself, antipattern! 2015-05-04 22:20:52 +01:00
Sebastian McKenzie
01e5354fd9 disallow replacing a node with itself 2015-05-04 22:20:52 +01:00
Sebastian McKenzie
0b100c4273 Merge pull request #1386 from jayphelps/module-id-overload
Added getModuleName() option as a function
2015-05-04 22:20:31 +01:00
Jay Phelps
340e75eb59 Added getModuleName() option as a function, allowing you to manipulate the name as needed 2015-05-04 13:30:57 -07:00
Sebastian McKenzie
53808a6d45 fix test/core/path imports 2015-05-04 15:25:35 +01:00
Sebastian McKenzie
e6326332b6 properly coerce input code to string - fixes #1432 2015-05-04 15:08:18 +01:00
Sebastian McKenzie
9e0cf84505 adds test for #1431 2015-05-04 15:06:27 +01:00
Sebastian McKenzie
b7eea7b08c Merge pull request #1431 from pangratz/fix_replaceWithSourceString
Fix bugs in `replaceWithSourceString`
2015-05-04 15:00:27 +01:00
pangratz
92dd67856e Fix bugs in replaceWithSourceString
This fixes 2 bugs within `replaceWithSourceString`:

- `code` is undefined as it should be `replacement`
- the expression of the parsed replacement hasn't been accessed correctly
2015-05-04 09:33:32 +02:00
Sebastian McKenzie
a2bb587e24 remove embedded jsx plugin and use acorn-jsx 2015-05-04 04:33:46 +01:00
Sebastian McKenzie
0c570cb599 5.2.9 2015-05-04 04:03:41 +01:00
Sebastian McKenzie
db6fab2c8f v5.2.9 2015-05-04 04:02:30 +01:00
Sebastian McKenzie
d92deb52b6 v5.2.8 2015-05-04 04:00:13 +01:00
Sebastian McKenzie
b8b70f2f4a rejigger around parse mechanics 2015-05-04 03:57:28 +01:00
Sebastian McKenzie
a8a3f6d34d Merge branch 'master' of github.com:babel/babel 2015-05-04 03:55:25 +01:00
Sebastian McKenzie
9847d226e1 add transform import - closes babel/babel-eslint#83 2015-05-04 03:54:58 +01:00
Sebastian McKenzie
3d48a16305 Merge pull request #1417 from loganfsmyth/fix-phantom-issue-1405
Explicitly sort instead of relying on key ordering.
2015-05-04 03:29:30 +01:00
Sebastian McKenzie
3d24cc9ae5 Merge pull request #1224 from jcoglan/fix-source-map-pathnames
Correct relative pathnames in source maps.
2015-05-04 00:03:27 +01:00
Sebastian McKenzie
5acc58dd68 5.2.7 2015-05-03 23:48:48 +01:00
Logan Smyth
74aaf848ed Explicitly sort instead of relying on implementation-defined numeric key ordering - fixes #1405. 2015-05-01 20:00:22 -07:00
James Coglan
1f2f4ce4f3 Correct relative pathnames in source maps.
Say you have a file called `src/thing.js` and you run

    $ babel src/thing.js --out-file lib/thing.js --source-maps true

This generates a source map at `lib/thing.js.map` that contains
"src/thing.js" in its `sources` array. This is incorrect; since browsers
resolve all relative URLs relative to the directory containing the file
that refers to the URL, this resolves to `lib/src/thing.js`.

To make the source map refer to the source files correctly, the
`sources` array should contain "../src/thing.js".
2015-04-13 21:17:11 +01:00
66 changed files with 785 additions and 1049 deletions

View File

@@ -13,6 +13,65 @@ _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.16
* **Bug Fix**
* Fix plugins being disabled when using the whitelist.
* Fix correct function scope being passed to `nameMethod.property` when inferring the function name for class methods.
* Fix incorrect extensions reference causing weird issues when using the Babel CLI.
* Fix destructuring param reference replacements not inheriting from their original param.
* **Spec Compliancy**
* Fix order that method decorators are ran in.
## 5.2.15
* **Bug Fix**
* Fix initializer descriptor add attempt if it doesn't exist.
## 5.2.14
* **Bug Fix**
* Fix bug with initializer decorators where the descriptors weren't being defined if there was no `initializer` property.
* **Internal**
* Expose `retainLines` option to CLI.
* Fix `retainLines` option not being taken into consideration when doing multiple variable declaration declarators generation.
* Expose minified and unminified copies of dist scripts.
## 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**

View File

@@ -82,9 +82,15 @@ publish:
npm version $$version --message "v%s"
make build
cp dist/babel.min.js browser.js
cp dist/polyfill.min.js browser-polyfill.js
cp dist/external-helpers.min.js external-helpers.js
cp dist/babel.js browser.js
cp dist/babel.min.js browser.min.js
cp dist/polyfill.js browser-polyfill.js
cp dist/polyfill.min.js browser-polyfill.min.js
cp dist/external-helpers.js external-helpers.js
cp dist/external-helpers.min.js external-helpers.min.js
node tools/cache-templates
test -f templates.json
@@ -96,7 +102,7 @@ publish:
make publish-cli
make publish-runtime
rm -rf templates.json browser.js browser-polyfill.js external-helpers.js
rm -rf templates.json browser.js browser.min.js browser-polyfill.js browser-polyfill.min.js external-helpers.js external-helpers.min.js
publish-runtime:
cd packages; \

View File

@@ -1,7 +1,7 @@
{
"name": "babel-core",
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
"version": "5.2.7",
"version": "5.2.16",
"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",

View File

@@ -55,6 +55,7 @@ babelArgs.forEach(function(arg){
case "--harmony_classes":
case "--harmony_object_literals":
case "--harmony_templates":
case "--harmony_rest_parameters":
case "--compiled_keyed_generic_loads":
case "--pretenuring_call_new":
case "--allocation_site_pretenuring":

View File

@@ -30,7 +30,7 @@ module.exports = function (commander, filenames, opts) {
var handleFile = function (src, filename) {
if (util.shouldIgnore(src)) return;
if (util.canCompile(filename, commander.extensions)) {
if (util.canCompile(filename, opts.extensions)) {
write(src, filename);
} else if (commander.copyFiles) {
outputFileSync(path.join(commander.outDir, filename), fs.readFileSync(src));

View File

@@ -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
});
});

View File

@@ -1,13 +1,13 @@
{
"name": "babel",
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
"version": "5.2.6",
"version": "5.2.15",
"author": "Sebastian McKenzie <sebmck@gmail.com>",
"homepage": "https://babeljs.io/",
"repository": "babel/babel",
"preferGlobal": true,
"dependencies": {
"babel-core": "^5.2.6",
"babel-core": "^5.2.15",
"chokidar": "^1.0.0",
"commander": "^2.6.0",
"convert-source-map": "^1.1.0",

View File

@@ -1,7 +1,7 @@
{
"name": "babel-runtime",
"description": "babel selfContained runtime",
"version": "5.2.6",
"version": "5.2.15",
"repository": "babel/babel",
"author": "Sebastian McKenzie <sebmck@gmail.com>",
"dependencies": {

View File

@@ -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);

View File

@@ -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);
}
};
});
}

View File

@@ -504,7 +504,7 @@ pp.parseClass = function(node, isStatement) {
this.parsePropertyName(method)
}
method.kind = "method"
if (!method.computed && !isGenerator) {
if (!method.computed && !isGenerator && !isAsync) {
if (method.key.type === "Identifier") {
if (this.type !== tt.parenL && (method.key.name === "get" || method.key.name === "set")) {
method.kind = method.key.name

View File

@@ -14,7 +14,6 @@ export { default as TransformerPipeline } from "../transformation/transformer-pi
export { default as traverse } from "../traversal";
export { default as buildExternalHelpers } from "../tools/build-external-helpers";
export { version } from "../../../package";
export { all as parse } from "../helpers/parse";
import * as t from "../types";
export { t as types };
@@ -54,5 +53,22 @@ 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 = {
flow: true,
jsx: true
};
opts.features = {};
for (var key in transform.pipeline.transformers) {
opts.features[key] = true;
}
return acorn.parse(code, opts);
}

View File

@@ -191,7 +191,7 @@ export function VariableDeclaration(node, print, parent) {
}
var sep = ",";
if (!this.format.compact && hasInits) {
if (!this.format.compact && hasInits && !this.format.retainLines) {
sep += `\n${repeating(" ", node.kind.length + 1)}`;
} else {
sep += " ";

View File

@@ -32,20 +32,3 @@ export default function (code, opts = {}) {
ast = normalizeAst(ast, comments, tokens);
return ast;
}
export function all(code, opts = {}) {
opts.allowHashBang = true;
opts.sourceType = "module";
opts.ecmaVersion = Infinity;
opts.plugins = {
flow: true,
jsx: true
};
opts.features = {};
for (var key in transform.pipeline.transformers) {
opts.features[key] = true;
}
return acorn.parse(code, opts);
}

View File

@@ -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",

View File

@@ -480,6 +480,8 @@ export default class File {
}
wrap(code, callback) {
code = code + "";
try {
if (this.shouldIgnore()) {
return {

View File

@@ -25,8 +25,11 @@
"type": "string"
},
"getModuleId": {
"hidden": true
},
"retainLines": {
"hidden": true,
"type": "boolean",
"default": false,
"description": "retain line numbers - will result in really ugly code"

View File

@@ -57,6 +57,9 @@ export default class PluginManager {
if (!plugin.buildPass || plugin.constructor.name !== "Transformer") {
throw new TypeError(messages.get("pluginNotTransformer", name));
}
// register as a plugin
plugin.metadata.plugin = true;
}
add(name) {

View File

@@ -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";

View File

@@ -26,7 +26,7 @@ export function push(mutatorMap, node, kind, file) {
if (node.decorators) {
var decorators = map.decorators = map.decorators || t.arrayExpression([]);
decorators.elements = decorators.elements.concat(node.decorators.map(dec => dec.expression));
decorators.elements = decorators.elements.concat(node.decorators.map(dec => dec.expression).reverse());
}
if (map.value || map.initializer) {

View File

@@ -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);
}
}

View File

@@ -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) {

View File

@@ -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) {

View File

@@ -28,8 +28,9 @@
if (descriptor.initializer) {
descriptor.value = descriptor.initializer.call(target);
Object.defineProperty(target, key, descriptor);
}
Object.defineProperty(target, key, descriptor);
}
return target;

View File

@@ -1,12 +1,12 @@
(function (target, key, descriptors) {
var _descriptor = descriptors[key];
if (!_descriptor) return;
// clone it
var descriptor = {};
for (var _key in _descriptor) descriptor[_key] = _descriptor[_key];
// initialize it
if (!descriptor.initializer) return;
descriptor.value = descriptor.initializer.call(target);
Object.defineProperty(target, key, descriptor);

View File

@@ -47,6 +47,8 @@ export default class TransformerPipeline {
}
canTransform(transformer, fileOpts) {
if (transformer.metadata.plugin) return true;
for (var filter of (this.filters: Array)) {
var result = filter(transformer, fileOpts);
if (result != null) return result;

View File

@@ -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++) {

View File

@@ -8,6 +8,4 @@ export function ArrowFunctionExpression(node) {
node.expression = false;
node.type = "FunctionExpression";
node.shadow = true;
return node;
}

View File

@@ -314,7 +314,7 @@ class ClassTransformer {
if (isConstructor) {
this.pushConstructor(node, path);
} else {
this.pushMethod(node);
this.pushMethod(node, path);
}
} else if (t.isClassProperty(node)) {
this.pushProperty(node);
@@ -412,7 +412,7 @@ class ClassTransformer {
this.pushMethod(t.methodDefinition(
t.identifier(PROPERTY_COLLISION_METHOD_NAME),
t.functionExpression(null, [], t.blockStatement(body))
), true);
), null, true);
if (this.hasSuper) {
this.bareSuper.insertAfter(call);
@@ -473,13 +473,13 @@ class ClassTransformer {
* Push a method to its respective mutatorMap.
*/
pushMethod(node: { type: "MethodDefinition" }, allowedIllegal?) {
pushMethod(node: { type: "MethodDefinition" }, path?: TraversalPath, allowedIllegal?) {
if (!allowedIllegal && t.isLiteral(t.toComputedKey(node), { value: PROPERTY_COLLISION_METHOD_NAME })) {
throw this.file.errorWithNode(node, messages.get("illegalMethodName", PROPERTY_COLLISION_METHOD_NAME));
}
if (node.kind === "method") {
nameMethod.property(node, this.file, this.scope);
nameMethod.property(node, this.file, path ? path.get("value").scope : this.scope);
if (this.isLoose) {
// use assignments instead of define properties for loose classes

View File

@@ -63,6 +63,7 @@ exports.Function = function (node, parent, scope, file) {
hasDestructuring = true;
var ref = scope.generateUidIdentifier("ref");
t.inherits(ref, pattern);
var destructuring = new DestructuringTransformer({
blockHoist: node.params.length - i,
@@ -82,7 +83,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 +105,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) {

View 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) {

View File

@@ -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();
};

View File

@@ -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();
};

View File

@@ -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

View File

@@ -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,54 +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.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;
@@ -75,7 +83,7 @@ var thirdPass = {
});
}
}
};
});
class TailCallTransformer {
constructor(path, scope, file) {

View File

@@ -1,7 +1,14 @@
export default {
_modules: require("./internal/modules"),
"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"),
"es7.trailingFunctionCommas": require("./es7/trailing-function-commas"),
"es7.asyncFunctions": require("./es7/async-functions"),
@@ -109,12 +116,6 @@ 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"),
"minification.memberExpressionLiterals": require("./minification/member-expression-literals"),
"minification.propertyLiterals": require("./minification/property-literals"),

View File

@@ -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;
});
}
};

View File

@@ -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")) {

View File

@@ -15,7 +15,7 @@ export default class Binding {
* Description
*/
setTypeAnnotation() {
setTypeAnnotation() {
var typeInfo = this.path.getTypeAnnotation();
this.typeAnnotationInferred = typeInfo.inferred;
this.typeAnnotation = typeInfo.annotation;

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -1,10 +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 { all as parse } from "../../helpers/parse";
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";
@@ -12,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) {
@@ -89,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
*/
@@ -481,7 +499,7 @@ export default class TraversalPath {
replaceWithSourceString(replacement) {
try {
replacement = `(${replacement})`;
replacement = parse(code);
replacement = parse(replacement);
} catch (err) {
var loc = err.loc;
if (loc) {
@@ -491,7 +509,7 @@ export default class TraversalPath {
throw err;
}
replacement = replacement.body[0].expression;
replacement = replacement.program.body[0].expression;
traverse.removeProperties(replacement);
return this.replaceWith(replacement);
}
@@ -509,9 +527,14 @@ 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)) {
@@ -657,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;
}
}
/**
@@ -924,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
*/
@@ -1082,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);

View 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);
}
};

View File

@@ -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,54 +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) {
var value = t.identifier(state.newName);;
ReferencedIdentifier(node, parent, scope, state) {
if (node.name !== state.oldName) return;
if (parent.value === state.binding) {
state.info.identifier = state.binding = value;
}
if (this.parentPath.isProperty() && this.key === "key" && parent.shorthand) {
var value = t.identifier(state.newName);;
parent.shorthand = false;
parent.value = value;
parent.key = t.identifier(state.oldName);
} else {
node.name = 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;
}
},
@@ -244,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);

View 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]);
}
}

View File

@@ -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 () {

View File

@@ -1,5 +1,5 @@
class Test {
constructor() {
arr.map(x => x * x);
arr.map(x => x * x);
}
}

View File

@@ -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;

View File

@@ -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"];

View File

@@ -1,5 +1,5 @@
"use strict";
var _import = require("foo");
var _foo = require("foo");
var foo = babelHelpers.interopRequireWildcard(_import);
var foo = babelHelpers.interopRequireWildcard(_foo);

View File

@@ -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;

View File

@@ -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;

View File

@@ -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"];

View File

@@ -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"];

View File

@@ -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;

View File

@@ -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"];

View File

@@ -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;

View File

@@ -0,0 +1,5 @@
class Foo {
t(t) {
return t;
}
}

View File

@@ -0,0 +1,15 @@
"use strict";
var Foo = (function () {
function Foo() {
babelHelpers.classCallCheck(this, Foo);
}
babelHelpers.createClass(Foo, [{
key: "t",
value: function t(_t) {
return _t;
}
}]);
return Foo;
})();

View File

@@ -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"];

View File

@@ -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"];

View File

@@ -0,0 +1 @@
class X { async constructor() {} }

View File

@@ -0,0 +1,4 @@
{
"throws": "Illegal kind for constructor method",
"optional": ["es7.asyncFunctions"]
}

View File

@@ -1,7 +1,7 @@
var generate = require("../../lib/babel/generation");
var assert = require("assert");
var helper = require("./_helper");
var parse = require("../../lib/babel/helpers/parse").default;
var parse = require("../../lib/babel/helpers/parse");
var chai = require("chai");
var t = require("../../lib/babel/types");
var _ = require("lodash");

21
test/core/path.js Normal file
View File

@@ -0,0 +1,21 @@
var Transformer = require("../../lib/babel/transformation/transformer");
var transform = require("../../lib/babel/transformation");
var babel = require("../../lib/babel/api/node");
var chai = require("chai");
suite("traversal path", function () {
test("replaceWithSourceString", function () {
var expectCode = "function foo() {}";
var actualCode = transform(expectCode, {
blacklist: "strict",
plugins: [new Transformer("foobar", {
FunctionDeclaration: function () {
return "console.whatever()";
}
})]
}).code;
chai.expect(actualCode).to.be.equal("console.whatever();");
});
});

View File

@@ -1,6 +1,6 @@
var assert = require("assert");
var util = require("../../lib/babel/util");
var parse = require("../../lib/babel/helpers/parse").default;
var parse = require("../../lib/babel/helpers/parse");
var t = require("../../lib/babel/types");
suite("util", function () {