Compare commits
22 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bbbf0a895d | ||
|
|
3289b33806 | ||
|
|
f4b9faa6b3 | ||
|
|
239b77816f | ||
|
|
8565e2b4e5 | ||
|
|
4317a46a3e | ||
|
|
81ca29adc3 | ||
|
|
c1a6ff7f44 | ||
|
|
7e6e5d4746 | ||
|
|
12d650e195 | ||
|
|
8fb58492df | ||
|
|
2c0c2f12df | ||
|
|
01e5354fd9 | ||
|
|
0b100c4273 | ||
|
|
340e75eb59 | ||
|
|
53808a6d45 | ||
|
|
e6326332b6 | ||
|
|
9e0cf84505 | ||
|
|
b7eea7b08c | ||
|
|
92dd67856e | ||
|
|
a2bb587e24 | ||
|
|
0c570cb599 |
18
CHANGELOG.md
18
CHANGELOG.md
@@ -13,6 +13,24 @@ _Note: Gaps between patch versions are faulty/broken releases._
|
|||||||
|
|
||||||
See [CHANGELOG - 6to5](CHANGELOG-6to5.md) for the pre-4.0.0 version changelog.
|
See [CHANGELOG - 6to5](CHANGELOG-6to5.md) for the pre-4.0.0 version changelog.
|
||||||
|
|
||||||
|
## 5.2.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
|
## 5.2.7
|
||||||
|
|
||||||
* **Bug Fix**
|
* **Bug Fix**
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "babel-core",
|
"name": "babel-core",
|
||||||
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
|
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
|
||||||
"version": "5.2.9",
|
"version": "5.2.12",
|
||||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||||
"homepage": "https://babeljs.io/",
|
"homepage": "https://babeljs.io/",
|
||||||
"repository": "babel/babel",
|
"repository": "babel/babel",
|
||||||
@@ -27,6 +27,7 @@
|
|||||||
"test": "make test"
|
"test": "make test"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"acorn-jsx": "^1.0.0",
|
||||||
"ast-types": "~0.7.0",
|
"ast-types": "~0.7.0",
|
||||||
"bluebird": "^2.9.25",
|
"bluebird": "^2.9.25",
|
||||||
"chalk": "^1.0.0",
|
"chalk": "^1.0.0",
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
{
|
{
|
||||||
"name": "babel",
|
"name": "babel",
|
||||||
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
|
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
|
||||||
"version": "5.2.7",
|
"version": "5.2.11",
|
||||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||||
"homepage": "https://babeljs.io/",
|
"homepage": "https://babeljs.io/",
|
||||||
"repository": "babel/babel",
|
"repository": "babel/babel",
|
||||||
"preferGlobal": true,
|
"preferGlobal": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"babel-core": "^5.2.7",
|
"babel-core": "^5.2.11",
|
||||||
"chokidar": "^1.0.0",
|
"chokidar": "^1.0.0",
|
||||||
"commander": "^2.6.0",
|
"commander": "^2.6.0",
|
||||||
"convert-source-map": "^1.1.0",
|
"convert-source-map": "^1.1.0",
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "babel-runtime",
|
"name": "babel-runtime",
|
||||||
"description": "babel selfContained runtime",
|
"description": "babel selfContained runtime",
|
||||||
"version": "5.2.7",
|
"version": "5.2.11",
|
||||||
"repository": "babel/babel",
|
"repository": "babel/babel",
|
||||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
export * from "./src/index";
|
export * from "./src/index";
|
||||||
import "./plugins/flow";
|
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);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
|
||||||
@@ -53,7 +53,7 @@ export function transformFile(filename: string, opts?: Object, callback: Functio
|
|||||||
|
|
||||||
export function transformFileSync(filename: string, opts?: Object = {}) {
|
export function transformFileSync(filename: string, opts?: Object = {}) {
|
||||||
opts.filename = filename;
|
opts.filename = filename;
|
||||||
return transform(fs.readFileSync(filename), opts);
|
return transform(fs.readFileSync(filename, "utf8"), opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function parse(code, opts = {}) {
|
export function parse(code, opts = {}) {
|
||||||
|
|||||||
@@ -480,6 +480,8 @@ export default class File {
|
|||||||
}
|
}
|
||||||
|
|
||||||
wrap(code, callback) {
|
wrap(code, callback) {
|
||||||
|
code = code + "";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (this.shouldIgnore()) {
|
if (this.shouldIgnore()) {
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -25,6 +25,10 @@
|
|||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"getModuleId": {
|
||||||
|
"hidden": true
|
||||||
|
},
|
||||||
|
|
||||||
"retainLines": {
|
"retainLines": {
|
||||||
"hidden": true,
|
"hidden": true,
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
|
|||||||
@@ -8,7 +8,8 @@ import * as t from "../../types";
|
|||||||
var remapVisitor = {
|
var remapVisitor = {
|
||||||
enter(node, parent, scope, formatter) {
|
enter(node, parent, scope, formatter) {
|
||||||
var remap = formatter.internalRemap[node.name];
|
var remap = formatter.internalRemap[node.name];
|
||||||
if (this.isReferencedIdentifier() && remap) {
|
|
||||||
|
if (this.isReferencedIdentifier() && remap && node !== remap) {
|
||||||
if (!scope.hasBinding(node.name) || scope.bindingIdentifierEquals(node.name, formatter.localImports[node.name])) {
|
if (!scope.hasBinding(node.name) || scope.bindingIdentifierEquals(node.name, formatter.localImports[node.name])) {
|
||||||
return remap;
|
return remap;
|
||||||
}
|
}
|
||||||
@@ -184,7 +185,10 @@ export default class DefaultFormatter {
|
|||||||
|
|
||||||
getModuleName() {
|
getModuleName() {
|
||||||
var opts = this.file.opts;
|
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 filenameRelative = opts.filenameRelative;
|
||||||
var moduleName = "";
|
var moduleName = "";
|
||||||
@@ -213,7 +217,12 @@ export default class DefaultFormatter {
|
|||||||
// normalize path separators
|
// normalize path separators
|
||||||
moduleName = moduleName.replace(/\\/g, "/");
|
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) {
|
_pushStatement(ref, nodes) {
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ export default class AMDFormatter extends DefaultFormatter {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
transform(program) {
|
transform(program) {
|
||||||
DefaultFormatter.prototype.transform.apply(this, arguments);
|
CommonFormatter.prototype.transform.apply(this, arguments);
|
||||||
|
|
||||||
var body = program.body;
|
var body = program.body;
|
||||||
|
|
||||||
@@ -108,12 +108,16 @@ export default class AMDFormatter extends DefaultFormatter {
|
|||||||
exportSpecifier(specifier, node, nodes) {
|
exportSpecifier(specifier, node, nodes) {
|
||||||
if (this.doDefaultExportInterop(specifier)) {
|
if (this.doDefaultExportInterop(specifier)) {
|
||||||
this.passModuleArg = true;
|
this.passModuleArg = true;
|
||||||
nodes.push(util.template("exports-default-assign", {
|
|
||||||
VALUE: specifier.local
|
if (specifier.exported !== specifier.local && !node.source) {
|
||||||
}, true));
|
nodes.push(util.template("exports-default-assign", {
|
||||||
} else {
|
VALUE: specifier.local
|
||||||
CommonFormatter.prototype.exportSpecifier.apply(this, arguments);
|
}, true));
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CommonFormatter.prototype.exportSpecifier.apply(this, arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
exportDeclaration(node, nodes) {
|
exportDeclaration(node, nodes) {
|
||||||
|
|||||||
@@ -8,6 +8,4 @@ export function ArrowFunctionExpression(node) {
|
|||||||
node.expression = false;
|
node.expression = false;
|
||||||
node.type = "FunctionExpression";
|
node.type = "FunctionExpression";
|
||||||
node.shadow = true;
|
node.shadow = true;
|
||||||
|
|
||||||
return node;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ exports.Function = function (node, parent, scope, file) {
|
|||||||
|
|
||||||
var block = node.body;
|
var block = node.body;
|
||||||
block.body = nodes.concat(block.body);
|
block.body = nodes.concat(block.body);
|
||||||
return node;
|
this.checkSelf();
|
||||||
};
|
};
|
||||||
|
|
||||||
export function CatchClause(node, parent, scope, file) {
|
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);
|
node.body.body = nodes.concat(node.body.body);
|
||||||
|
|
||||||
return node;
|
this.checkSelf();
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ExpressionStatement(node, parent, scope, file) {
|
export function ExpressionStatement(node, parent, scope, file) {
|
||||||
|
|||||||
@@ -97,5 +97,5 @@ exports.Function = function (node, parent, scope, file) {
|
|||||||
node.body.body = body.concat(node.body.body);
|
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);
|
candidate.replaceWith(argsId);
|
||||||
optimizeMemberExpression(candidate.parent, node.params.length);
|
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;
|
loop._blockHoist = node.params.length + 1;
|
||||||
node.body.body.unshift(loop);
|
node.body.body.unshift(loop);
|
||||||
return node;
|
this.checkSelf();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -481,7 +481,7 @@ export default class TraversalPath {
|
|||||||
replaceWithSourceString(replacement) {
|
replaceWithSourceString(replacement) {
|
||||||
try {
|
try {
|
||||||
replacement = `(${replacement})`;
|
replacement = `(${replacement})`;
|
||||||
replacement = parse(code);
|
replacement = parse(replacement);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
var loc = err.loc;
|
var loc = err.loc;
|
||||||
if (loc) {
|
if (loc) {
|
||||||
@@ -491,7 +491,7 @@ export default class TraversalPath {
|
|||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
|
|
||||||
replacement = replacement.body[0].expression;
|
replacement = replacement.program.body[0].expression;
|
||||||
traverse.removeProperties(replacement);
|
traverse.removeProperties(replacement);
|
||||||
return this.replaceWith(replacement);
|
return this.replaceWith(replacement);
|
||||||
}
|
}
|
||||||
@@ -509,9 +509,14 @@ export default class TraversalPath {
|
|||||||
throw new Error("You passed `path.replaceWith()` a falsy node, use `path.remove()` instead");
|
throw new Error("You passed `path.replaceWith()` a falsy node, use `path.remove()` instead");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.node === replacement) {
|
||||||
|
return this.checkSelf();
|
||||||
|
}
|
||||||
|
|
||||||
// normalise inserting an entire AST
|
// normalise inserting an entire AST
|
||||||
if (t.isProgram(replacement)) {
|
if (t.isProgram(replacement)) {
|
||||||
replacement = replacement.body;
|
replacement = replacement.body;
|
||||||
|
whateverAllowed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Array.isArray(replacement)) {
|
if (Array.isArray(replacement)) {
|
||||||
|
|||||||
@@ -244,12 +244,14 @@ export default class Scope {
|
|||||||
|
|
||||||
var add = function (node) {
|
var add = function (node) {
|
||||||
if (t.isModuleDeclaration(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++) {
|
for (var i = 0; i < node.specifiers.length; i++) {
|
||||||
add(node.specifiers[i]);
|
add(node.specifiers[i]);
|
||||||
}
|
}
|
||||||
} else {
|
} else if (node.declaration) {
|
||||||
add(node.source);
|
add(node.declaration);
|
||||||
}
|
}
|
||||||
} else if (t.isModuleSpecifier(node)) {
|
} else if (t.isModuleSpecifier(node)) {
|
||||||
add(node.local);
|
add(node.local);
|
||||||
|
|||||||
@@ -18,6 +18,77 @@ suite("api", function () {
|
|||||||
assert.ok(!result.ast);
|
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 () {
|
test("addHelper unknown", function () {
|
||||||
var file = new File({}, transform.pipeline);
|
var file = new File({}, transform.pipeline);
|
||||||
assert.throws(function () {
|
assert.throws(function () {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
class Test {
|
class Test {
|
||||||
constructor() {
|
constructor() {
|
||||||
arr.map(x => x * x);
|
arr.map(x => x * x);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,15 +5,15 @@ Object.defineProperty(exports, "__esModule", {
|
|||||||
});
|
});
|
||||||
exports.nextOdd = nextOdd;
|
exports.nextOdd = nextOdd;
|
||||||
|
|
||||||
var _isEven = require("./evens");
|
var _evens = require("./evens");
|
||||||
|
|
||||||
function nextOdd(n) {
|
function nextOdd(n) {
|
||||||
return _isEven.isEven(n) ? n + 1 : n + 2;
|
return _evens.isEven(n) ? n + 1 : n + 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
var isOdd = (function (isEven) {
|
var isOdd = (function (isEven) {
|
||||||
return function (n) {
|
return function (n) {
|
||||||
return !isEven(n);
|
return !isEven(n);
|
||||||
};
|
};
|
||||||
})(_isEven.isEven);
|
})(_evens.isEven);
|
||||||
exports.isOdd = isOdd;
|
exports.isOdd = isOdd;
|
||||||
@@ -4,7 +4,7 @@ var _foo = require("foo");
|
|||||||
|
|
||||||
var _foo2 = babelHelpers.interopRequireDefault(_foo);
|
var _foo2 = babelHelpers.interopRequireDefault(_foo);
|
||||||
|
|
||||||
var _foo22 = babelHelpers.interopRequireDefault(_foo);
|
var _foo3 = babelHelpers.interopRequireDefault(_foo);
|
||||||
|
|
||||||
_foo2["default"];
|
_foo2["default"];
|
||||||
_foo22["default"];
|
_foo3["default"];
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
"use strict";
|
"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";
|
"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"];
|
_foo2["default"];
|
||||||
_foo$xyz.baz;
|
_foo.baz;
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var _bar = require("foo");
|
var _foo = require("foo");
|
||||||
|
|
||||||
_bar.bar;
|
_foo.bar;
|
||||||
_bar.bar2;
|
_foo.bar2;
|
||||||
_bar.baz;
|
_foo.baz;
|
||||||
_bar.bar;
|
_foo.bar;
|
||||||
_bar.bar;
|
_foo.bar;
|
||||||
_bar.xyz;
|
_foo.xyz;
|
||||||
@@ -10,22 +10,22 @@ require("foo-bar");
|
|||||||
|
|
||||||
require("./directory/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;
|
exports.test = test;
|
||||||
var test = 5;
|
var test = 5;
|
||||||
|
|
||||||
exports.test = test;
|
exports.test = test;
|
||||||
_bar.bar;
|
_foo4.bar;
|
||||||
_bar2.foo;
|
_foo5.foo;
|
||||||
_foo2["default"];
|
_foo22["default"];
|
||||||
@@ -4,8 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|||||||
value: true
|
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
|
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;
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
"use strict";
|
"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;
|
exports.giveWord = giveWord;
|
||||||
var marked0$0 = [giveWord].map(_regeneratorRuntime.mark);
|
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");
|
var myWord = _Symbol("abc");
|
||||||
exports.myWord = myWord;
|
exports.myWord = myWord;
|
||||||
@@ -40,5 +40,5 @@ function giveWord() {
|
|||||||
}, marked0$0[0], this);
|
}, marked0$0[0], this);
|
||||||
}
|
}
|
||||||
|
|
||||||
_foo2["default"];
|
_someModule2["default"];
|
||||||
bar;
|
bar;
|
||||||
@@ -4,9 +4,9 @@ Object.defineProperty(exports, "__esModule", {
|
|||||||
value: true
|
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 () {
|
var Container = (function () {
|
||||||
function Container() {
|
function Container() {
|
||||||
@@ -20,11 +20,11 @@ var Container = (function () {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
return _last3["default"](this.tokens.get(key));
|
return _lodashArrayLast2["default"](this.tokens.get(key));
|
||||||
}
|
}
|
||||||
}]);
|
}]);
|
||||||
return Container;
|
return Container;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
exports["default"] = Container;
|
exports["default"] = Container;
|
||||||
module.exports = exports["default"];
|
module.exports = exports["default"];
|
||||||
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|||||||
value: true
|
value: true
|
||||||
});
|
});
|
||||||
|
|
||||||
var _getForm2 = require("./store");
|
var _store = require("./store");
|
||||||
|
|
||||||
var Login = (function (_React$Component) {
|
var Login = (function (_React$Component) {
|
||||||
function Login() {
|
function Login() {
|
||||||
@@ -19,11 +19,11 @@ var Login = (function (_React$Component) {
|
|||||||
babelHelpers.createClass(Login, [{
|
babelHelpers.createClass(Login, [{
|
||||||
key: "getForm",
|
key: "getForm",
|
||||||
value: function getForm() {
|
value: function getForm() {
|
||||||
return _getForm2.getForm().toJS();
|
return _store.getForm().toJS();
|
||||||
}
|
}
|
||||||
}]);
|
}]);
|
||||||
return Login;
|
return Login;
|
||||||
})(React.Component);
|
})(React.Component);
|
||||||
|
|
||||||
exports["default"] = Login;
|
exports["default"] = Login;
|
||||||
module.exports = exports["default"];
|
module.exports = exports["default"];
|
||||||
21
test/core/path.js
Normal file
21
test/core/path.js
Normal 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();");
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user