jslike 1.5.0 → 1.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/interpreter/interpreter.js +312 -20
- package/dist/esm/parser.js +781 -3
- package/dist/esm/runtime/builtins.js +14 -0
- package/dist/index.cjs +931 -20
- package/dist/index.d.cts +1070 -30
- package/dist/index.d.ts +1070 -30
- package/dist/index.js +931 -20
- package/dist/validator/index.cjs +669 -5
- package/dist/validator/index.js +669 -5
- package/package.json +5 -2
package/dist/esm/parser.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Self-contained Acorn parser (bundled for zero runtime dependencies)
|
|
2
|
+
* Self-contained Acorn parser with JSX support (bundled for zero runtime dependencies)
|
|
3
3
|
* Acorn is MIT licensed: https://github.com/acornjs/acorn
|
|
4
|
+
* Acorn-JSX is MIT licensed: https://github.com/acornjs/acorn-jsx
|
|
4
5
|
* This file is auto-generated by scripts/bundle-acorn.js
|
|
5
|
-
* Original size: ~224KB
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
// This file was generated. Do not modify manually!
|
|
@@ -6237,5 +6237,783 @@ function tokenizer(input, options) {
|
|
|
6237
6237
|
return Parser.tokenizer(input, options)
|
|
6238
6238
|
}
|
|
6239
6239
|
|
|
6240
|
-
|
|
6240
|
+
// Original exports removed - see bottom of file
|
|
6241
|
+
|
|
6242
|
+
// ========== JSX Plugin (acorn-jsx) ==========
|
|
6243
|
+
|
|
6244
|
+
'use strict';
|
|
6245
|
+
|
|
6246
|
+
const XHTMLEntities = {
|
|
6247
|
+
quot: '\u0022',
|
|
6248
|
+
amp: '&',
|
|
6249
|
+
apos: '\u0027',
|
|
6250
|
+
lt: '<',
|
|
6251
|
+
gt: '>',
|
|
6252
|
+
nbsp: '\u00A0',
|
|
6253
|
+
iexcl: '\u00A1',
|
|
6254
|
+
cent: '\u00A2',
|
|
6255
|
+
pound: '\u00A3',
|
|
6256
|
+
curren: '\u00A4',
|
|
6257
|
+
yen: '\u00A5',
|
|
6258
|
+
brvbar: '\u00A6',
|
|
6259
|
+
sect: '\u00A7',
|
|
6260
|
+
uml: '\u00A8',
|
|
6261
|
+
copy: '\u00A9',
|
|
6262
|
+
ordf: '\u00AA',
|
|
6263
|
+
laquo: '\u00AB',
|
|
6264
|
+
not: '\u00AC',
|
|
6265
|
+
shy: '\u00AD',
|
|
6266
|
+
reg: '\u00AE',
|
|
6267
|
+
macr: '\u00AF',
|
|
6268
|
+
deg: '\u00B0',
|
|
6269
|
+
plusmn: '\u00B1',
|
|
6270
|
+
sup2: '\u00B2',
|
|
6271
|
+
sup3: '\u00B3',
|
|
6272
|
+
acute: '\u00B4',
|
|
6273
|
+
micro: '\u00B5',
|
|
6274
|
+
para: '\u00B6',
|
|
6275
|
+
middot: '\u00B7',
|
|
6276
|
+
cedil: '\u00B8',
|
|
6277
|
+
sup1: '\u00B9',
|
|
6278
|
+
ordm: '\u00BA',
|
|
6279
|
+
raquo: '\u00BB',
|
|
6280
|
+
frac14: '\u00BC',
|
|
6281
|
+
frac12: '\u00BD',
|
|
6282
|
+
frac34: '\u00BE',
|
|
6283
|
+
iquest: '\u00BF',
|
|
6284
|
+
Agrave: '\u00C0',
|
|
6285
|
+
Aacute: '\u00C1',
|
|
6286
|
+
Acirc: '\u00C2',
|
|
6287
|
+
Atilde: '\u00C3',
|
|
6288
|
+
Auml: '\u00C4',
|
|
6289
|
+
Aring: '\u00C5',
|
|
6290
|
+
AElig: '\u00C6',
|
|
6291
|
+
Ccedil: '\u00C7',
|
|
6292
|
+
Egrave: '\u00C8',
|
|
6293
|
+
Eacute: '\u00C9',
|
|
6294
|
+
Ecirc: '\u00CA',
|
|
6295
|
+
Euml: '\u00CB',
|
|
6296
|
+
Igrave: '\u00CC',
|
|
6297
|
+
Iacute: '\u00CD',
|
|
6298
|
+
Icirc: '\u00CE',
|
|
6299
|
+
Iuml: '\u00CF',
|
|
6300
|
+
ETH: '\u00D0',
|
|
6301
|
+
Ntilde: '\u00D1',
|
|
6302
|
+
Ograve: '\u00D2',
|
|
6303
|
+
Oacute: '\u00D3',
|
|
6304
|
+
Ocirc: '\u00D4',
|
|
6305
|
+
Otilde: '\u00D5',
|
|
6306
|
+
Ouml: '\u00D6',
|
|
6307
|
+
times: '\u00D7',
|
|
6308
|
+
Oslash: '\u00D8',
|
|
6309
|
+
Ugrave: '\u00D9',
|
|
6310
|
+
Uacute: '\u00DA',
|
|
6311
|
+
Ucirc: '\u00DB',
|
|
6312
|
+
Uuml: '\u00DC',
|
|
6313
|
+
Yacute: '\u00DD',
|
|
6314
|
+
THORN: '\u00DE',
|
|
6315
|
+
szlig: '\u00DF',
|
|
6316
|
+
agrave: '\u00E0',
|
|
6317
|
+
aacute: '\u00E1',
|
|
6318
|
+
acirc: '\u00E2',
|
|
6319
|
+
atilde: '\u00E3',
|
|
6320
|
+
auml: '\u00E4',
|
|
6321
|
+
aring: '\u00E5',
|
|
6322
|
+
aelig: '\u00E6',
|
|
6323
|
+
ccedil: '\u00E7',
|
|
6324
|
+
egrave: '\u00E8',
|
|
6325
|
+
eacute: '\u00E9',
|
|
6326
|
+
ecirc: '\u00EA',
|
|
6327
|
+
euml: '\u00EB',
|
|
6328
|
+
igrave: '\u00EC',
|
|
6329
|
+
iacute: '\u00ED',
|
|
6330
|
+
icirc: '\u00EE',
|
|
6331
|
+
iuml: '\u00EF',
|
|
6332
|
+
eth: '\u00F0',
|
|
6333
|
+
ntilde: '\u00F1',
|
|
6334
|
+
ograve: '\u00F2',
|
|
6335
|
+
oacute: '\u00F3',
|
|
6336
|
+
ocirc: '\u00F4',
|
|
6337
|
+
otilde: '\u00F5',
|
|
6338
|
+
ouml: '\u00F6',
|
|
6339
|
+
divide: '\u00F7',
|
|
6340
|
+
oslash: '\u00F8',
|
|
6341
|
+
ugrave: '\u00F9',
|
|
6342
|
+
uacute: '\u00FA',
|
|
6343
|
+
ucirc: '\u00FB',
|
|
6344
|
+
uuml: '\u00FC',
|
|
6345
|
+
yacute: '\u00FD',
|
|
6346
|
+
thorn: '\u00FE',
|
|
6347
|
+
yuml: '\u00FF',
|
|
6348
|
+
OElig: '\u0152',
|
|
6349
|
+
oelig: '\u0153',
|
|
6350
|
+
Scaron: '\u0160',
|
|
6351
|
+
scaron: '\u0161',
|
|
6352
|
+
Yuml: '\u0178',
|
|
6353
|
+
fnof: '\u0192',
|
|
6354
|
+
circ: '\u02C6',
|
|
6355
|
+
tilde: '\u02DC',
|
|
6356
|
+
Alpha: '\u0391',
|
|
6357
|
+
Beta: '\u0392',
|
|
6358
|
+
Gamma: '\u0393',
|
|
6359
|
+
Delta: '\u0394',
|
|
6360
|
+
Epsilon: '\u0395',
|
|
6361
|
+
Zeta: '\u0396',
|
|
6362
|
+
Eta: '\u0397',
|
|
6363
|
+
Theta: '\u0398',
|
|
6364
|
+
Iota: '\u0399',
|
|
6365
|
+
Kappa: '\u039A',
|
|
6366
|
+
Lambda: '\u039B',
|
|
6367
|
+
Mu: '\u039C',
|
|
6368
|
+
Nu: '\u039D',
|
|
6369
|
+
Xi: '\u039E',
|
|
6370
|
+
Omicron: '\u039F',
|
|
6371
|
+
Pi: '\u03A0',
|
|
6372
|
+
Rho: '\u03A1',
|
|
6373
|
+
Sigma: '\u03A3',
|
|
6374
|
+
Tau: '\u03A4',
|
|
6375
|
+
Upsilon: '\u03A5',
|
|
6376
|
+
Phi: '\u03A6',
|
|
6377
|
+
Chi: '\u03A7',
|
|
6378
|
+
Psi: '\u03A8',
|
|
6379
|
+
Omega: '\u03A9',
|
|
6380
|
+
alpha: '\u03B1',
|
|
6381
|
+
beta: '\u03B2',
|
|
6382
|
+
gamma: '\u03B3',
|
|
6383
|
+
delta: '\u03B4',
|
|
6384
|
+
epsilon: '\u03B5',
|
|
6385
|
+
zeta: '\u03B6',
|
|
6386
|
+
eta: '\u03B7',
|
|
6387
|
+
theta: '\u03B8',
|
|
6388
|
+
iota: '\u03B9',
|
|
6389
|
+
kappa: '\u03BA',
|
|
6390
|
+
lambda: '\u03BB',
|
|
6391
|
+
mu: '\u03BC',
|
|
6392
|
+
nu: '\u03BD',
|
|
6393
|
+
xi: '\u03BE',
|
|
6394
|
+
omicron: '\u03BF',
|
|
6395
|
+
pi: '\u03C0',
|
|
6396
|
+
rho: '\u03C1',
|
|
6397
|
+
sigmaf: '\u03C2',
|
|
6398
|
+
sigma: '\u03C3',
|
|
6399
|
+
tau: '\u03C4',
|
|
6400
|
+
upsilon: '\u03C5',
|
|
6401
|
+
phi: '\u03C6',
|
|
6402
|
+
chi: '\u03C7',
|
|
6403
|
+
psi: '\u03C8',
|
|
6404
|
+
omega: '\u03C9',
|
|
6405
|
+
thetasym: '\u03D1',
|
|
6406
|
+
upsih: '\u03D2',
|
|
6407
|
+
piv: '\u03D6',
|
|
6408
|
+
ensp: '\u2002',
|
|
6409
|
+
emsp: '\u2003',
|
|
6410
|
+
thinsp: '\u2009',
|
|
6411
|
+
zwnj: '\u200C',
|
|
6412
|
+
zwj: '\u200D',
|
|
6413
|
+
lrm: '\u200E',
|
|
6414
|
+
rlm: '\u200F',
|
|
6415
|
+
ndash: '\u2013',
|
|
6416
|
+
mdash: '\u2014',
|
|
6417
|
+
lsquo: '\u2018',
|
|
6418
|
+
rsquo: '\u2019',
|
|
6419
|
+
sbquo: '\u201A',
|
|
6420
|
+
ldquo: '\u201C',
|
|
6421
|
+
rdquo: '\u201D',
|
|
6422
|
+
bdquo: '\u201E',
|
|
6423
|
+
dagger: '\u2020',
|
|
6424
|
+
Dagger: '\u2021',
|
|
6425
|
+
bull: '\u2022',
|
|
6426
|
+
hellip: '\u2026',
|
|
6427
|
+
permil: '\u2030',
|
|
6428
|
+
prime: '\u2032',
|
|
6429
|
+
Prime: '\u2033',
|
|
6430
|
+
lsaquo: '\u2039',
|
|
6431
|
+
rsaquo: '\u203A',
|
|
6432
|
+
oline: '\u203E',
|
|
6433
|
+
frasl: '\u2044',
|
|
6434
|
+
euro: '\u20AC',
|
|
6435
|
+
image: '\u2111',
|
|
6436
|
+
weierp: '\u2118',
|
|
6437
|
+
real: '\u211C',
|
|
6438
|
+
trade: '\u2122',
|
|
6439
|
+
alefsym: '\u2135',
|
|
6440
|
+
larr: '\u2190',
|
|
6441
|
+
uarr: '\u2191',
|
|
6442
|
+
rarr: '\u2192',
|
|
6443
|
+
darr: '\u2193',
|
|
6444
|
+
harr: '\u2194',
|
|
6445
|
+
crarr: '\u21B5',
|
|
6446
|
+
lArr: '\u21D0',
|
|
6447
|
+
uArr: '\u21D1',
|
|
6448
|
+
rArr: '\u21D2',
|
|
6449
|
+
dArr: '\u21D3',
|
|
6450
|
+
hArr: '\u21D4',
|
|
6451
|
+
forall: '\u2200',
|
|
6452
|
+
part: '\u2202',
|
|
6453
|
+
exist: '\u2203',
|
|
6454
|
+
empty: '\u2205',
|
|
6455
|
+
nabla: '\u2207',
|
|
6456
|
+
isin: '\u2208',
|
|
6457
|
+
notin: '\u2209',
|
|
6458
|
+
ni: '\u220B',
|
|
6459
|
+
prod: '\u220F',
|
|
6460
|
+
sum: '\u2211',
|
|
6461
|
+
minus: '\u2212',
|
|
6462
|
+
lowast: '\u2217',
|
|
6463
|
+
radic: '\u221A',
|
|
6464
|
+
prop: '\u221D',
|
|
6465
|
+
infin: '\u221E',
|
|
6466
|
+
ang: '\u2220',
|
|
6467
|
+
and: '\u2227',
|
|
6468
|
+
or: '\u2228',
|
|
6469
|
+
cap: '\u2229',
|
|
6470
|
+
cup: '\u222A',
|
|
6471
|
+
'int': '\u222B',
|
|
6472
|
+
there4: '\u2234',
|
|
6473
|
+
sim: '\u223C',
|
|
6474
|
+
cong: '\u2245',
|
|
6475
|
+
asymp: '\u2248',
|
|
6476
|
+
ne: '\u2260',
|
|
6477
|
+
equiv: '\u2261',
|
|
6478
|
+
le: '\u2264',
|
|
6479
|
+
ge: '\u2265',
|
|
6480
|
+
sub: '\u2282',
|
|
6481
|
+
sup: '\u2283',
|
|
6482
|
+
nsub: '\u2284',
|
|
6483
|
+
sube: '\u2286',
|
|
6484
|
+
supe: '\u2287',
|
|
6485
|
+
oplus: '\u2295',
|
|
6486
|
+
otimes: '\u2297',
|
|
6487
|
+
perp: '\u22A5',
|
|
6488
|
+
sdot: '\u22C5',
|
|
6489
|
+
lceil: '\u2308',
|
|
6490
|
+
rceil: '\u2309',
|
|
6491
|
+
lfloor: '\u230A',
|
|
6492
|
+
rfloor: '\u230B',
|
|
6493
|
+
lang: '\u2329',
|
|
6494
|
+
rang: '\u232A',
|
|
6495
|
+
loz: '\u25CA',
|
|
6496
|
+
spades: '\u2660',
|
|
6497
|
+
clubs: '\u2663',
|
|
6498
|
+
hearts: '\u2665',
|
|
6499
|
+
diams: '\u2666'
|
|
6500
|
+
};
|
|
6501
|
+
|
|
6502
|
+
const hexNumber = /^[\da-fA-F]+$/;
|
|
6503
|
+
const decimalNumber = /^\d+$/;
|
|
6504
|
+
|
|
6505
|
+
// The map to `acorn-jsx` tokens from `acorn` namespace objects.
|
|
6506
|
+
const acornJsxMap = new WeakMap();
|
|
6507
|
+
|
|
6508
|
+
// Get the original tokens for the given `acorn` namespace object.
|
|
6509
|
+
function getJsxTokens(acorn) {
|
|
6510
|
+
acorn = acorn.Parser.acorn || acorn;
|
|
6511
|
+
let acornJsx = acornJsxMap.get(acorn);
|
|
6512
|
+
if (!acornJsx) {
|
|
6513
|
+
const tt = acorn.tokTypes;
|
|
6514
|
+
const TokContext = acorn.TokContext;
|
|
6515
|
+
const TokenType = acorn.TokenType;
|
|
6516
|
+
const tc_oTag = new TokContext('<tag', false);
|
|
6517
|
+
const tc_cTag = new TokContext('</tag', false);
|
|
6518
|
+
const tc_expr = new TokContext('<tag>...</tag>', true, true);
|
|
6519
|
+
const tokContexts = {
|
|
6520
|
+
tc_oTag: tc_oTag,
|
|
6521
|
+
tc_cTag: tc_cTag,
|
|
6522
|
+
tc_expr: tc_expr
|
|
6523
|
+
};
|
|
6524
|
+
const tokTypes = {
|
|
6525
|
+
jsxName: new TokenType('jsxName'),
|
|
6526
|
+
jsxText: new TokenType('jsxText', {beforeExpr: true}),
|
|
6527
|
+
jsxTagStart: new TokenType('jsxTagStart', {startsExpr: true}),
|
|
6528
|
+
jsxTagEnd: new TokenType('jsxTagEnd')
|
|
6529
|
+
};
|
|
6530
|
+
|
|
6531
|
+
tokTypes.jsxTagStart.updateContext = function() {
|
|
6532
|
+
this.context.push(tc_expr); // treat as beginning of JSX expression
|
|
6533
|
+
this.context.push(tc_oTag); // start opening tag context
|
|
6534
|
+
this.exprAllowed = false;
|
|
6535
|
+
};
|
|
6536
|
+
tokTypes.jsxTagEnd.updateContext = function(prevType) {
|
|
6537
|
+
let out = this.context.pop();
|
|
6538
|
+
if (out === tc_oTag && prevType === tt.slash || out === tc_cTag) {
|
|
6539
|
+
this.context.pop();
|
|
6540
|
+
this.exprAllowed = this.curContext() === tc_expr;
|
|
6541
|
+
} else {
|
|
6542
|
+
this.exprAllowed = true;
|
|
6543
|
+
}
|
|
6544
|
+
};
|
|
6545
|
+
|
|
6546
|
+
acornJsx = { tokContexts: tokContexts, tokTypes: tokTypes };
|
|
6547
|
+
acornJsxMap.set(acorn, acornJsx);
|
|
6548
|
+
}
|
|
6549
|
+
|
|
6550
|
+
return acornJsx;
|
|
6551
|
+
}
|
|
6552
|
+
|
|
6553
|
+
// Transforms JSX element name to string.
|
|
6554
|
+
|
|
6555
|
+
function getQualifiedJSXName(object) {
|
|
6556
|
+
if (!object)
|
|
6557
|
+
return object;
|
|
6558
|
+
|
|
6559
|
+
if (object.type === 'JSXIdentifier')
|
|
6560
|
+
return object.name;
|
|
6561
|
+
|
|
6562
|
+
if (object.type === 'JSXNamespacedName')
|
|
6563
|
+
return object.namespace.name + ':' + object.name.name;
|
|
6564
|
+
|
|
6565
|
+
if (object.type === 'JSXMemberExpression')
|
|
6566
|
+
return getQualifiedJSXName(object.object) + '.' +
|
|
6567
|
+
getQualifiedJSXName(object.property);
|
|
6568
|
+
}
|
|
6569
|
+
|
|
6570
|
+
function acornJsx(options) {
|
|
6571
|
+
options = options || {};
|
|
6572
|
+
return function(Parser) {
|
|
6573
|
+
return plugin({
|
|
6574
|
+
allowNamespaces: options.allowNamespaces !== false,
|
|
6575
|
+
allowNamespacedObjects: !!options.allowNamespacedObjects
|
|
6576
|
+
}, Parser);
|
|
6577
|
+
};
|
|
6578
|
+
};
|
|
6579
|
+
|
|
6580
|
+
// This is `tokTypes` of the peer dep.
|
|
6581
|
+
// This can be different instances from the actual `tokTypes` this plugin uses.
|
|
6582
|
+
// tokTypes property removed for bundle
|
|
6583
|
+
|
|
6584
|
+
function plugin(options, Parser) {
|
|
6585
|
+
const acorn = Parser.acorn || { tokTypes: tt, TokContext, TokenType, isNewLine, isIdentifierStart, isIdentifierChar, tokContexts };
|
|
6586
|
+
const acornJsx = getJsxTokens(acorn);
|
|
6587
|
+
const tt = acorn.tokTypes;
|
|
6588
|
+
const tok = acornJsx.tokTypes;
|
|
6589
|
+
const tokContexts = acorn.tokContexts;
|
|
6590
|
+
const tc_oTag = acornJsx.tokContexts.tc_oTag;
|
|
6591
|
+
const tc_cTag = acornJsx.tokContexts.tc_cTag;
|
|
6592
|
+
const tc_expr = acornJsx.tokContexts.tc_expr;
|
|
6593
|
+
const isNewLine = acorn.isNewLine;
|
|
6594
|
+
const isIdentifierStart = acorn.isIdentifierStart;
|
|
6595
|
+
const isIdentifierChar = acorn.isIdentifierChar;
|
|
6596
|
+
|
|
6597
|
+
return class extends Parser {
|
|
6598
|
+
// Expose actual `tokTypes` and `tokContexts` to other plugins.
|
|
6599
|
+
static get acornJsx() {
|
|
6600
|
+
return acornJsx;
|
|
6601
|
+
}
|
|
6602
|
+
|
|
6603
|
+
// Reads inline JSX contents token.
|
|
6604
|
+
jsx_readToken() {
|
|
6605
|
+
let out = '', chunkStart = this.pos;
|
|
6606
|
+
for (;;) {
|
|
6607
|
+
if (this.pos >= this.input.length)
|
|
6608
|
+
this.raise(this.start, 'Unterminated JSX contents');
|
|
6609
|
+
let ch = this.input.charCodeAt(this.pos);
|
|
6610
|
+
|
|
6611
|
+
switch (ch) {
|
|
6612
|
+
case 60: // '<'
|
|
6613
|
+
case 123: // '{'
|
|
6614
|
+
if (this.pos === this.start) {
|
|
6615
|
+
if (ch === 60 && this.exprAllowed) {
|
|
6616
|
+
++this.pos;
|
|
6617
|
+
return this.finishToken(tok.jsxTagStart);
|
|
6618
|
+
}
|
|
6619
|
+
return this.getTokenFromCode(ch);
|
|
6620
|
+
}
|
|
6621
|
+
out += this.input.slice(chunkStart, this.pos);
|
|
6622
|
+
return this.finishToken(tok.jsxText, out);
|
|
6623
|
+
|
|
6624
|
+
case 38: // '&'
|
|
6625
|
+
out += this.input.slice(chunkStart, this.pos);
|
|
6626
|
+
out += this.jsx_readEntity();
|
|
6627
|
+
chunkStart = this.pos;
|
|
6628
|
+
break;
|
|
6629
|
+
|
|
6630
|
+
case 62: // '>'
|
|
6631
|
+
case 125: // '}'
|
|
6632
|
+
this.raise(
|
|
6633
|
+
this.pos,
|
|
6634
|
+
"Unexpected token `" + this.input[this.pos] + "`. Did you mean `" +
|
|
6635
|
+
(ch === 62 ? ">" : "}") + "` or " + "`{\"" + this.input[this.pos] + "\"}" + "`?"
|
|
6636
|
+
);
|
|
6637
|
+
|
|
6638
|
+
default:
|
|
6639
|
+
if (isNewLine(ch)) {
|
|
6640
|
+
out += this.input.slice(chunkStart, this.pos);
|
|
6641
|
+
out += this.jsx_readNewLine(true);
|
|
6642
|
+
chunkStart = this.pos;
|
|
6643
|
+
} else {
|
|
6644
|
+
++this.pos;
|
|
6645
|
+
}
|
|
6646
|
+
}
|
|
6647
|
+
}
|
|
6648
|
+
}
|
|
6649
|
+
|
|
6650
|
+
jsx_readNewLine(normalizeCRLF) {
|
|
6651
|
+
let ch = this.input.charCodeAt(this.pos);
|
|
6652
|
+
let out;
|
|
6653
|
+
++this.pos;
|
|
6654
|
+
if (ch === 13 && this.input.charCodeAt(this.pos) === 10) {
|
|
6655
|
+
++this.pos;
|
|
6656
|
+
out = normalizeCRLF ? '\n' : '\r\n';
|
|
6657
|
+
} else {
|
|
6658
|
+
out = String.fromCharCode(ch);
|
|
6659
|
+
}
|
|
6660
|
+
if (this.options.locations) {
|
|
6661
|
+
++this.curLine;
|
|
6662
|
+
this.lineStart = this.pos;
|
|
6663
|
+
}
|
|
6664
|
+
|
|
6665
|
+
return out;
|
|
6666
|
+
}
|
|
6667
|
+
|
|
6668
|
+
jsx_readString(quote) {
|
|
6669
|
+
let out = '', chunkStart = ++this.pos;
|
|
6670
|
+
for (;;) {
|
|
6671
|
+
if (this.pos >= this.input.length)
|
|
6672
|
+
this.raise(this.start, 'Unterminated string constant');
|
|
6673
|
+
let ch = this.input.charCodeAt(this.pos);
|
|
6674
|
+
if (ch === quote) break;
|
|
6675
|
+
if (ch === 38) { // '&'
|
|
6676
|
+
out += this.input.slice(chunkStart, this.pos);
|
|
6677
|
+
out += this.jsx_readEntity();
|
|
6678
|
+
chunkStart = this.pos;
|
|
6679
|
+
} else if (isNewLine(ch)) {
|
|
6680
|
+
out += this.input.slice(chunkStart, this.pos);
|
|
6681
|
+
out += this.jsx_readNewLine(false);
|
|
6682
|
+
chunkStart = this.pos;
|
|
6683
|
+
} else {
|
|
6684
|
+
++this.pos;
|
|
6685
|
+
}
|
|
6686
|
+
}
|
|
6687
|
+
out += this.input.slice(chunkStart, this.pos++);
|
|
6688
|
+
return this.finishToken(tt.string, out);
|
|
6689
|
+
}
|
|
6690
|
+
|
|
6691
|
+
jsx_readEntity() {
|
|
6692
|
+
let str = '', count = 0, entity;
|
|
6693
|
+
let ch = this.input[this.pos];
|
|
6694
|
+
if (ch !== '&')
|
|
6695
|
+
this.raise(this.pos, 'Entity must start with an ampersand');
|
|
6696
|
+
let startPos = ++this.pos;
|
|
6697
|
+
while (this.pos < this.input.length && count++ < 10) {
|
|
6698
|
+
ch = this.input[this.pos++];
|
|
6699
|
+
if (ch === ';') {
|
|
6700
|
+
if (str[0] === '#') {
|
|
6701
|
+
if (str[1] === 'x') {
|
|
6702
|
+
str = str.substr(2);
|
|
6703
|
+
if (hexNumber.test(str))
|
|
6704
|
+
entity = String.fromCharCode(parseInt(str, 16));
|
|
6705
|
+
} else {
|
|
6706
|
+
str = str.substr(1);
|
|
6707
|
+
if (decimalNumber.test(str))
|
|
6708
|
+
entity = String.fromCharCode(parseInt(str, 10));
|
|
6709
|
+
}
|
|
6710
|
+
} else {
|
|
6711
|
+
entity = XHTMLEntities[str];
|
|
6712
|
+
}
|
|
6713
|
+
break;
|
|
6714
|
+
}
|
|
6715
|
+
str += ch;
|
|
6716
|
+
}
|
|
6717
|
+
if (!entity) {
|
|
6718
|
+
this.pos = startPos;
|
|
6719
|
+
return '&';
|
|
6720
|
+
}
|
|
6721
|
+
return entity;
|
|
6722
|
+
}
|
|
6723
|
+
|
|
6724
|
+
// Read a JSX identifier (valid tag or attribute name).
|
|
6725
|
+
//
|
|
6726
|
+
// Optimized version since JSX identifiers can't contain
|
|
6727
|
+
// escape characters and so can be read as single slice.
|
|
6728
|
+
// Also assumes that first character was already checked
|
|
6729
|
+
// by isIdentifierStart in readToken.
|
|
6730
|
+
|
|
6731
|
+
jsx_readWord() {
|
|
6732
|
+
let ch, start = this.pos;
|
|
6733
|
+
do {
|
|
6734
|
+
ch = this.input.charCodeAt(++this.pos);
|
|
6735
|
+
} while (isIdentifierChar(ch) || ch === 45); // '-'
|
|
6736
|
+
return this.finishToken(tok.jsxName, this.input.slice(start, this.pos));
|
|
6737
|
+
}
|
|
6738
|
+
|
|
6739
|
+
// Parse next token as JSX identifier
|
|
6740
|
+
|
|
6741
|
+
jsx_parseIdentifier() {
|
|
6742
|
+
let node = this.startNode();
|
|
6743
|
+
if (this.type === tok.jsxName)
|
|
6744
|
+
node.name = this.value;
|
|
6745
|
+
else if (this.type.keyword)
|
|
6746
|
+
node.name = this.type.keyword;
|
|
6747
|
+
else
|
|
6748
|
+
this.unexpected();
|
|
6749
|
+
this.next();
|
|
6750
|
+
return this.finishNode(node, 'JSXIdentifier');
|
|
6751
|
+
}
|
|
6752
|
+
|
|
6753
|
+
// Parse namespaced identifier.
|
|
6754
|
+
|
|
6755
|
+
jsx_parseNamespacedName() {
|
|
6756
|
+
let startPos = this.start, startLoc = this.startLoc;
|
|
6757
|
+
let name = this.jsx_parseIdentifier();
|
|
6758
|
+
if (!options.allowNamespaces || !this.eat(tt.colon)) return name;
|
|
6759
|
+
var node = this.startNodeAt(startPos, startLoc);
|
|
6760
|
+
node.namespace = name;
|
|
6761
|
+
node.name = this.jsx_parseIdentifier();
|
|
6762
|
+
return this.finishNode(node, 'JSXNamespacedName');
|
|
6763
|
+
}
|
|
6764
|
+
|
|
6765
|
+
// Parses element name in any form - namespaced, member
|
|
6766
|
+
// or single identifier.
|
|
6767
|
+
|
|
6768
|
+
jsx_parseElementName() {
|
|
6769
|
+
if (this.type === tok.jsxTagEnd) return '';
|
|
6770
|
+
let startPos = this.start, startLoc = this.startLoc;
|
|
6771
|
+
let node = this.jsx_parseNamespacedName();
|
|
6772
|
+
if (this.type === tt.dot && node.type === 'JSXNamespacedName' && !options.allowNamespacedObjects) {
|
|
6773
|
+
this.unexpected();
|
|
6774
|
+
}
|
|
6775
|
+
while (this.eat(tt.dot)) {
|
|
6776
|
+
let newNode = this.startNodeAt(startPos, startLoc);
|
|
6777
|
+
newNode.object = node;
|
|
6778
|
+
newNode.property = this.jsx_parseIdentifier();
|
|
6779
|
+
node = this.finishNode(newNode, 'JSXMemberExpression');
|
|
6780
|
+
}
|
|
6781
|
+
return node;
|
|
6782
|
+
}
|
|
6241
6783
|
|
|
6784
|
+
// Parses any type of JSX attribute value.
|
|
6785
|
+
|
|
6786
|
+
jsx_parseAttributeValue() {
|
|
6787
|
+
switch (this.type) {
|
|
6788
|
+
case tt.braceL:
|
|
6789
|
+
let node = this.jsx_parseExpressionContainer();
|
|
6790
|
+
if (node.expression.type === 'JSXEmptyExpression')
|
|
6791
|
+
this.raise(node.start, 'JSX attributes must only be assigned a non-empty expression');
|
|
6792
|
+
return node;
|
|
6793
|
+
|
|
6794
|
+
case tok.jsxTagStart:
|
|
6795
|
+
case tt.string:
|
|
6796
|
+
return this.parseExprAtom();
|
|
6797
|
+
|
|
6798
|
+
default:
|
|
6799
|
+
this.raise(this.start, 'JSX value should be either an expression or a quoted JSX text');
|
|
6800
|
+
}
|
|
6801
|
+
}
|
|
6802
|
+
|
|
6803
|
+
// JSXEmptyExpression is unique type since it doesn't actually parse anything,
|
|
6804
|
+
// and so it should start at the end of last read token (left brace) and finish
|
|
6805
|
+
// at the beginning of the next one (right brace).
|
|
6806
|
+
|
|
6807
|
+
jsx_parseEmptyExpression() {
|
|
6808
|
+
let node = this.startNodeAt(this.lastTokEnd, this.lastTokEndLoc);
|
|
6809
|
+
return this.finishNodeAt(node, 'JSXEmptyExpression', this.start, this.startLoc);
|
|
6810
|
+
}
|
|
6811
|
+
|
|
6812
|
+
// Parses JSX expression enclosed into curly brackets.
|
|
6813
|
+
|
|
6814
|
+
jsx_parseExpressionContainer() {
|
|
6815
|
+
let node = this.startNode();
|
|
6816
|
+
this.next();
|
|
6817
|
+
node.expression = this.type === tt.braceR
|
|
6818
|
+
? this.jsx_parseEmptyExpression()
|
|
6819
|
+
: this.parseExpression();
|
|
6820
|
+
this.expect(tt.braceR);
|
|
6821
|
+
return this.finishNode(node, 'JSXExpressionContainer');
|
|
6822
|
+
}
|
|
6823
|
+
|
|
6824
|
+
// Parses following JSX attribute name-value pair.
|
|
6825
|
+
|
|
6826
|
+
jsx_parseAttribute() {
|
|
6827
|
+
let node = this.startNode();
|
|
6828
|
+
if (this.eat(tt.braceL)) {
|
|
6829
|
+
this.expect(tt.ellipsis);
|
|
6830
|
+
node.argument = this.parseMaybeAssign();
|
|
6831
|
+
this.expect(tt.braceR);
|
|
6832
|
+
return this.finishNode(node, 'JSXSpreadAttribute');
|
|
6833
|
+
}
|
|
6834
|
+
node.name = this.jsx_parseNamespacedName();
|
|
6835
|
+
node.value = this.eat(tt.eq) ? this.jsx_parseAttributeValue() : null;
|
|
6836
|
+
return this.finishNode(node, 'JSXAttribute');
|
|
6837
|
+
}
|
|
6838
|
+
|
|
6839
|
+
// Parses JSX opening tag starting after '<'.
|
|
6840
|
+
|
|
6841
|
+
jsx_parseOpeningElementAt(startPos, startLoc) {
|
|
6842
|
+
let node = this.startNodeAt(startPos, startLoc);
|
|
6843
|
+
node.attributes = [];
|
|
6844
|
+
let nodeName = this.jsx_parseElementName();
|
|
6845
|
+
if (nodeName) node.name = nodeName;
|
|
6846
|
+
while (this.type !== tt.slash && this.type !== tok.jsxTagEnd)
|
|
6847
|
+
node.attributes.push(this.jsx_parseAttribute());
|
|
6848
|
+
node.selfClosing = this.eat(tt.slash);
|
|
6849
|
+
this.expect(tok.jsxTagEnd);
|
|
6850
|
+
return this.finishNode(node, nodeName ? 'JSXOpeningElement' : 'JSXOpeningFragment');
|
|
6851
|
+
}
|
|
6852
|
+
|
|
6853
|
+
// Parses JSX closing tag starting after '</'.
|
|
6854
|
+
|
|
6855
|
+
jsx_parseClosingElementAt(startPos, startLoc) {
|
|
6856
|
+
let node = this.startNodeAt(startPos, startLoc);
|
|
6857
|
+
let nodeName = this.jsx_parseElementName();
|
|
6858
|
+
if (nodeName) node.name = nodeName;
|
|
6859
|
+
this.expect(tok.jsxTagEnd);
|
|
6860
|
+
return this.finishNode(node, nodeName ? 'JSXClosingElement' : 'JSXClosingFragment');
|
|
6861
|
+
}
|
|
6862
|
+
|
|
6863
|
+
// Parses entire JSX element, including it's opening tag
|
|
6864
|
+
// (starting after '<'), attributes, contents and closing tag.
|
|
6865
|
+
|
|
6866
|
+
jsx_parseElementAt(startPos, startLoc) {
|
|
6867
|
+
let node = this.startNodeAt(startPos, startLoc);
|
|
6868
|
+
let children = [];
|
|
6869
|
+
let openingElement = this.jsx_parseOpeningElementAt(startPos, startLoc);
|
|
6870
|
+
let closingElement = null;
|
|
6871
|
+
|
|
6872
|
+
if (!openingElement.selfClosing) {
|
|
6873
|
+
contents: for (;;) {
|
|
6874
|
+
switch (this.type) {
|
|
6875
|
+
case tok.jsxTagStart:
|
|
6876
|
+
startPos = this.start; startLoc = this.startLoc;
|
|
6877
|
+
this.next();
|
|
6878
|
+
if (this.eat(tt.slash)) {
|
|
6879
|
+
closingElement = this.jsx_parseClosingElementAt(startPos, startLoc);
|
|
6880
|
+
break contents;
|
|
6881
|
+
}
|
|
6882
|
+
children.push(this.jsx_parseElementAt(startPos, startLoc));
|
|
6883
|
+
break;
|
|
6884
|
+
|
|
6885
|
+
case tok.jsxText:
|
|
6886
|
+
children.push(this.parseExprAtom());
|
|
6887
|
+
break;
|
|
6888
|
+
|
|
6889
|
+
case tt.braceL:
|
|
6890
|
+
children.push(this.jsx_parseExpressionContainer());
|
|
6891
|
+
break;
|
|
6892
|
+
|
|
6893
|
+
default:
|
|
6894
|
+
this.unexpected();
|
|
6895
|
+
}
|
|
6896
|
+
}
|
|
6897
|
+
if (getQualifiedJSXName(closingElement.name) !== getQualifiedJSXName(openingElement.name)) {
|
|
6898
|
+
this.raise(
|
|
6899
|
+
closingElement.start,
|
|
6900
|
+
'Expected corresponding JSX closing tag for <' + getQualifiedJSXName(openingElement.name) + '>');
|
|
6901
|
+
}
|
|
6902
|
+
}
|
|
6903
|
+
let fragmentOrElement = openingElement.name ? 'Element' : 'Fragment';
|
|
6904
|
+
|
|
6905
|
+
node['opening' + fragmentOrElement] = openingElement;
|
|
6906
|
+
node['closing' + fragmentOrElement] = closingElement;
|
|
6907
|
+
node.children = children;
|
|
6908
|
+
if (this.type === tt.relational && this.value === "<") {
|
|
6909
|
+
this.raise(this.start, "Adjacent JSX elements must be wrapped in an enclosing tag");
|
|
6910
|
+
}
|
|
6911
|
+
return this.finishNode(node, 'JSX' + fragmentOrElement);
|
|
6912
|
+
}
|
|
6913
|
+
|
|
6914
|
+
// Parse JSX text
|
|
6915
|
+
|
|
6916
|
+
jsx_parseText() {
|
|
6917
|
+
let node = this.parseLiteral(this.value);
|
|
6918
|
+
node.type = "JSXText";
|
|
6919
|
+
return node;
|
|
6920
|
+
}
|
|
6921
|
+
|
|
6922
|
+
// Parses entire JSX element from current position.
|
|
6923
|
+
|
|
6924
|
+
jsx_parseElement() {
|
|
6925
|
+
let startPos = this.start, startLoc = this.startLoc;
|
|
6926
|
+
this.next();
|
|
6927
|
+
return this.jsx_parseElementAt(startPos, startLoc);
|
|
6928
|
+
}
|
|
6929
|
+
|
|
6930
|
+
parseExprAtom(refShortHandDefaultPos) {
|
|
6931
|
+
if (this.type === tok.jsxText)
|
|
6932
|
+
return this.jsx_parseText();
|
|
6933
|
+
else if (this.type === tok.jsxTagStart)
|
|
6934
|
+
return this.jsx_parseElement();
|
|
6935
|
+
else
|
|
6936
|
+
return super.parseExprAtom(refShortHandDefaultPos);
|
|
6937
|
+
}
|
|
6938
|
+
|
|
6939
|
+
readToken(code) {
|
|
6940
|
+
let context = this.curContext();
|
|
6941
|
+
|
|
6942
|
+
if (context === tc_expr) return this.jsx_readToken();
|
|
6943
|
+
|
|
6944
|
+
if (context === tc_oTag || context === tc_cTag) {
|
|
6945
|
+
if (isIdentifierStart(code)) return this.jsx_readWord();
|
|
6946
|
+
|
|
6947
|
+
if (code == 62) {
|
|
6948
|
+
++this.pos;
|
|
6949
|
+
return this.finishToken(tok.jsxTagEnd);
|
|
6950
|
+
}
|
|
6951
|
+
|
|
6952
|
+
if ((code === 34 || code === 39) && context == tc_oTag)
|
|
6953
|
+
return this.jsx_readString(code);
|
|
6954
|
+
}
|
|
6955
|
+
|
|
6956
|
+
if (code === 60 && this.exprAllowed && this.input.charCodeAt(this.pos + 1) !== 33) {
|
|
6957
|
+
++this.pos;
|
|
6958
|
+
return this.finishToken(tok.jsxTagStart);
|
|
6959
|
+
}
|
|
6960
|
+
return super.readToken(code);
|
|
6961
|
+
}
|
|
6962
|
+
|
|
6963
|
+
updateContext(prevType) {
|
|
6964
|
+
if (this.type == tt.braceL) {
|
|
6965
|
+
var curContext = this.curContext();
|
|
6966
|
+
if (curContext == tc_oTag) this.context.push(tokContexts.b_expr);
|
|
6967
|
+
else if (curContext == tc_expr) this.context.push(tokContexts.b_tmpl);
|
|
6968
|
+
else super.updateContext(prevType);
|
|
6969
|
+
this.exprAllowed = true;
|
|
6970
|
+
} else if (this.type === tt.slash && prevType === tok.jsxTagStart) {
|
|
6971
|
+
this.context.length -= 2; // do not consider JSX expr -> JSX open tag -> ... anymore
|
|
6972
|
+
this.context.push(tc_cTag); // reconsider as closing tag context
|
|
6973
|
+
this.exprAllowed = false;
|
|
6974
|
+
} else {
|
|
6975
|
+
return super.updateContext(prevType);
|
|
6976
|
+
}
|
|
6977
|
+
}
|
|
6978
|
+
};
|
|
6979
|
+
}
|
|
6980
|
+
|
|
6981
|
+
|
|
6982
|
+
// ========== Create JSX-enabled Parser ==========
|
|
6983
|
+
|
|
6984
|
+
const JSXParser = Parser.extend(acornJsx());
|
|
6985
|
+
|
|
6986
|
+
// JSX-aware parse function that replaces the original
|
|
6987
|
+
function jsxParse(input, options) {
|
|
6988
|
+
return JSXParser.parse(input, options);
|
|
6989
|
+
}
|
|
6990
|
+
|
|
6991
|
+
// Alias internal names for external use
|
|
6992
|
+
const tokTypes = types$1;
|
|
6993
|
+
const tokContexts = types;
|
|
6994
|
+
|
|
6995
|
+
// Export with JSX support - parse now uses JSX-enabled parser
|
|
6996
|
+
export {
|
|
6997
|
+
jsxParse as parse,
|
|
6998
|
+
Parser,
|
|
6999
|
+
JSXParser,
|
|
7000
|
+
tokenizer,
|
|
7001
|
+
defaultOptions,
|
|
7002
|
+
tokTypes,
|
|
7003
|
+
TokContext,
|
|
7004
|
+
TokenType,
|
|
7005
|
+
isNewLine,
|
|
7006
|
+
isIdentifierStart,
|
|
7007
|
+
isIdentifierChar,
|
|
7008
|
+
tokContexts,
|
|
7009
|
+
Node,
|
|
7010
|
+
Position,
|
|
7011
|
+
SourceLocation,
|
|
7012
|
+
Token,
|
|
7013
|
+
getLineInfo,
|
|
7014
|
+
lineBreak,
|
|
7015
|
+
lineBreakG,
|
|
7016
|
+
nonASCIIwhitespace,
|
|
7017
|
+
parseExpressionAt,
|
|
7018
|
+
version
|
|
7019
|
+
};
|