jslike 1.4.5 → 1.6.0
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/index.js +51 -25
- package/dist/esm/interpreter/index.js +2 -1
- package/dist/esm/interpreter/interpreter.js +370 -26
- package/dist/esm/parser.js +781 -3
- package/dist/esm/runtime/builtins.js +14 -0
- package/dist/esm/runtime/execution-controller.js +212 -0
- package/dist/index.cjs +1199 -41
- package/dist/index.d.cts +1394 -63
- package/dist/index.d.ts +1394 -63
- package/dist/index.js +1198 -41
- package/dist/validator/index.cjs +669 -5
- package/dist/validator/index.js +669 -5
- package/package.json +5 -2
package/dist/validator/index.cjs
CHANGED
|
@@ -5631,8 +5631,672 @@ Parser.acorn = {
|
|
|
5631
5631
|
lineBreakG,
|
|
5632
5632
|
nonASCIIwhitespace
|
|
5633
5633
|
};
|
|
5634
|
-
|
|
5635
|
-
|
|
5634
|
+
var XHTMLEntities = {
|
|
5635
|
+
quot: '"',
|
|
5636
|
+
amp: "&",
|
|
5637
|
+
apos: "'",
|
|
5638
|
+
lt: "<",
|
|
5639
|
+
gt: ">",
|
|
5640
|
+
nbsp: "\xA0",
|
|
5641
|
+
iexcl: "\xA1",
|
|
5642
|
+
cent: "\xA2",
|
|
5643
|
+
pound: "\xA3",
|
|
5644
|
+
curren: "\xA4",
|
|
5645
|
+
yen: "\xA5",
|
|
5646
|
+
brvbar: "\xA6",
|
|
5647
|
+
sect: "\xA7",
|
|
5648
|
+
uml: "\xA8",
|
|
5649
|
+
copy: "\xA9",
|
|
5650
|
+
ordf: "\xAA",
|
|
5651
|
+
laquo: "\xAB",
|
|
5652
|
+
not: "\xAC",
|
|
5653
|
+
shy: "\xAD",
|
|
5654
|
+
reg: "\xAE",
|
|
5655
|
+
macr: "\xAF",
|
|
5656
|
+
deg: "\xB0",
|
|
5657
|
+
plusmn: "\xB1",
|
|
5658
|
+
sup2: "\xB2",
|
|
5659
|
+
sup3: "\xB3",
|
|
5660
|
+
acute: "\xB4",
|
|
5661
|
+
micro: "\xB5",
|
|
5662
|
+
para: "\xB6",
|
|
5663
|
+
middot: "\xB7",
|
|
5664
|
+
cedil: "\xB8",
|
|
5665
|
+
sup1: "\xB9",
|
|
5666
|
+
ordm: "\xBA",
|
|
5667
|
+
raquo: "\xBB",
|
|
5668
|
+
frac14: "\xBC",
|
|
5669
|
+
frac12: "\xBD",
|
|
5670
|
+
frac34: "\xBE",
|
|
5671
|
+
iquest: "\xBF",
|
|
5672
|
+
Agrave: "\xC0",
|
|
5673
|
+
Aacute: "\xC1",
|
|
5674
|
+
Acirc: "\xC2",
|
|
5675
|
+
Atilde: "\xC3",
|
|
5676
|
+
Auml: "\xC4",
|
|
5677
|
+
Aring: "\xC5",
|
|
5678
|
+
AElig: "\xC6",
|
|
5679
|
+
Ccedil: "\xC7",
|
|
5680
|
+
Egrave: "\xC8",
|
|
5681
|
+
Eacute: "\xC9",
|
|
5682
|
+
Ecirc: "\xCA",
|
|
5683
|
+
Euml: "\xCB",
|
|
5684
|
+
Igrave: "\xCC",
|
|
5685
|
+
Iacute: "\xCD",
|
|
5686
|
+
Icirc: "\xCE",
|
|
5687
|
+
Iuml: "\xCF",
|
|
5688
|
+
ETH: "\xD0",
|
|
5689
|
+
Ntilde: "\xD1",
|
|
5690
|
+
Ograve: "\xD2",
|
|
5691
|
+
Oacute: "\xD3",
|
|
5692
|
+
Ocirc: "\xD4",
|
|
5693
|
+
Otilde: "\xD5",
|
|
5694
|
+
Ouml: "\xD6",
|
|
5695
|
+
times: "\xD7",
|
|
5696
|
+
Oslash: "\xD8",
|
|
5697
|
+
Ugrave: "\xD9",
|
|
5698
|
+
Uacute: "\xDA",
|
|
5699
|
+
Ucirc: "\xDB",
|
|
5700
|
+
Uuml: "\xDC",
|
|
5701
|
+
Yacute: "\xDD",
|
|
5702
|
+
THORN: "\xDE",
|
|
5703
|
+
szlig: "\xDF",
|
|
5704
|
+
agrave: "\xE0",
|
|
5705
|
+
aacute: "\xE1",
|
|
5706
|
+
acirc: "\xE2",
|
|
5707
|
+
atilde: "\xE3",
|
|
5708
|
+
auml: "\xE4",
|
|
5709
|
+
aring: "\xE5",
|
|
5710
|
+
aelig: "\xE6",
|
|
5711
|
+
ccedil: "\xE7",
|
|
5712
|
+
egrave: "\xE8",
|
|
5713
|
+
eacute: "\xE9",
|
|
5714
|
+
ecirc: "\xEA",
|
|
5715
|
+
euml: "\xEB",
|
|
5716
|
+
igrave: "\xEC",
|
|
5717
|
+
iacute: "\xED",
|
|
5718
|
+
icirc: "\xEE",
|
|
5719
|
+
iuml: "\xEF",
|
|
5720
|
+
eth: "\xF0",
|
|
5721
|
+
ntilde: "\xF1",
|
|
5722
|
+
ograve: "\xF2",
|
|
5723
|
+
oacute: "\xF3",
|
|
5724
|
+
ocirc: "\xF4",
|
|
5725
|
+
otilde: "\xF5",
|
|
5726
|
+
ouml: "\xF6",
|
|
5727
|
+
divide: "\xF7",
|
|
5728
|
+
oslash: "\xF8",
|
|
5729
|
+
ugrave: "\xF9",
|
|
5730
|
+
uacute: "\xFA",
|
|
5731
|
+
ucirc: "\xFB",
|
|
5732
|
+
uuml: "\xFC",
|
|
5733
|
+
yacute: "\xFD",
|
|
5734
|
+
thorn: "\xFE",
|
|
5735
|
+
yuml: "\xFF",
|
|
5736
|
+
OElig: "\u0152",
|
|
5737
|
+
oelig: "\u0153",
|
|
5738
|
+
Scaron: "\u0160",
|
|
5739
|
+
scaron: "\u0161",
|
|
5740
|
+
Yuml: "\u0178",
|
|
5741
|
+
fnof: "\u0192",
|
|
5742
|
+
circ: "\u02C6",
|
|
5743
|
+
tilde: "\u02DC",
|
|
5744
|
+
Alpha: "\u0391",
|
|
5745
|
+
Beta: "\u0392",
|
|
5746
|
+
Gamma: "\u0393",
|
|
5747
|
+
Delta: "\u0394",
|
|
5748
|
+
Epsilon: "\u0395",
|
|
5749
|
+
Zeta: "\u0396",
|
|
5750
|
+
Eta: "\u0397",
|
|
5751
|
+
Theta: "\u0398",
|
|
5752
|
+
Iota: "\u0399",
|
|
5753
|
+
Kappa: "\u039A",
|
|
5754
|
+
Lambda: "\u039B",
|
|
5755
|
+
Mu: "\u039C",
|
|
5756
|
+
Nu: "\u039D",
|
|
5757
|
+
Xi: "\u039E",
|
|
5758
|
+
Omicron: "\u039F",
|
|
5759
|
+
Pi: "\u03A0",
|
|
5760
|
+
Rho: "\u03A1",
|
|
5761
|
+
Sigma: "\u03A3",
|
|
5762
|
+
Tau: "\u03A4",
|
|
5763
|
+
Upsilon: "\u03A5",
|
|
5764
|
+
Phi: "\u03A6",
|
|
5765
|
+
Chi: "\u03A7",
|
|
5766
|
+
Psi: "\u03A8",
|
|
5767
|
+
Omega: "\u03A9",
|
|
5768
|
+
alpha: "\u03B1",
|
|
5769
|
+
beta: "\u03B2",
|
|
5770
|
+
gamma: "\u03B3",
|
|
5771
|
+
delta: "\u03B4",
|
|
5772
|
+
epsilon: "\u03B5",
|
|
5773
|
+
zeta: "\u03B6",
|
|
5774
|
+
eta: "\u03B7",
|
|
5775
|
+
theta: "\u03B8",
|
|
5776
|
+
iota: "\u03B9",
|
|
5777
|
+
kappa: "\u03BA",
|
|
5778
|
+
lambda: "\u03BB",
|
|
5779
|
+
mu: "\u03BC",
|
|
5780
|
+
nu: "\u03BD",
|
|
5781
|
+
xi: "\u03BE",
|
|
5782
|
+
omicron: "\u03BF",
|
|
5783
|
+
pi: "\u03C0",
|
|
5784
|
+
rho: "\u03C1",
|
|
5785
|
+
sigmaf: "\u03C2",
|
|
5786
|
+
sigma: "\u03C3",
|
|
5787
|
+
tau: "\u03C4",
|
|
5788
|
+
upsilon: "\u03C5",
|
|
5789
|
+
phi: "\u03C6",
|
|
5790
|
+
chi: "\u03C7",
|
|
5791
|
+
psi: "\u03C8",
|
|
5792
|
+
omega: "\u03C9",
|
|
5793
|
+
thetasym: "\u03D1",
|
|
5794
|
+
upsih: "\u03D2",
|
|
5795
|
+
piv: "\u03D6",
|
|
5796
|
+
ensp: "\u2002",
|
|
5797
|
+
emsp: "\u2003",
|
|
5798
|
+
thinsp: "\u2009",
|
|
5799
|
+
zwnj: "\u200C",
|
|
5800
|
+
zwj: "\u200D",
|
|
5801
|
+
lrm: "\u200E",
|
|
5802
|
+
rlm: "\u200F",
|
|
5803
|
+
ndash: "\u2013",
|
|
5804
|
+
mdash: "\u2014",
|
|
5805
|
+
lsquo: "\u2018",
|
|
5806
|
+
rsquo: "\u2019",
|
|
5807
|
+
sbquo: "\u201A",
|
|
5808
|
+
ldquo: "\u201C",
|
|
5809
|
+
rdquo: "\u201D",
|
|
5810
|
+
bdquo: "\u201E",
|
|
5811
|
+
dagger: "\u2020",
|
|
5812
|
+
Dagger: "\u2021",
|
|
5813
|
+
bull: "\u2022",
|
|
5814
|
+
hellip: "\u2026",
|
|
5815
|
+
permil: "\u2030",
|
|
5816
|
+
prime: "\u2032",
|
|
5817
|
+
Prime: "\u2033",
|
|
5818
|
+
lsaquo: "\u2039",
|
|
5819
|
+
rsaquo: "\u203A",
|
|
5820
|
+
oline: "\u203E",
|
|
5821
|
+
frasl: "\u2044",
|
|
5822
|
+
euro: "\u20AC",
|
|
5823
|
+
image: "\u2111",
|
|
5824
|
+
weierp: "\u2118",
|
|
5825
|
+
real: "\u211C",
|
|
5826
|
+
trade: "\u2122",
|
|
5827
|
+
alefsym: "\u2135",
|
|
5828
|
+
larr: "\u2190",
|
|
5829
|
+
uarr: "\u2191",
|
|
5830
|
+
rarr: "\u2192",
|
|
5831
|
+
darr: "\u2193",
|
|
5832
|
+
harr: "\u2194",
|
|
5833
|
+
crarr: "\u21B5",
|
|
5834
|
+
lArr: "\u21D0",
|
|
5835
|
+
uArr: "\u21D1",
|
|
5836
|
+
rArr: "\u21D2",
|
|
5837
|
+
dArr: "\u21D3",
|
|
5838
|
+
hArr: "\u21D4",
|
|
5839
|
+
forall: "\u2200",
|
|
5840
|
+
part: "\u2202",
|
|
5841
|
+
exist: "\u2203",
|
|
5842
|
+
empty: "\u2205",
|
|
5843
|
+
nabla: "\u2207",
|
|
5844
|
+
isin: "\u2208",
|
|
5845
|
+
notin: "\u2209",
|
|
5846
|
+
ni: "\u220B",
|
|
5847
|
+
prod: "\u220F",
|
|
5848
|
+
sum: "\u2211",
|
|
5849
|
+
minus: "\u2212",
|
|
5850
|
+
lowast: "\u2217",
|
|
5851
|
+
radic: "\u221A",
|
|
5852
|
+
prop: "\u221D",
|
|
5853
|
+
infin: "\u221E",
|
|
5854
|
+
ang: "\u2220",
|
|
5855
|
+
and: "\u2227",
|
|
5856
|
+
or: "\u2228",
|
|
5857
|
+
cap: "\u2229",
|
|
5858
|
+
cup: "\u222A",
|
|
5859
|
+
"int": "\u222B",
|
|
5860
|
+
there4: "\u2234",
|
|
5861
|
+
sim: "\u223C",
|
|
5862
|
+
cong: "\u2245",
|
|
5863
|
+
asymp: "\u2248",
|
|
5864
|
+
ne: "\u2260",
|
|
5865
|
+
equiv: "\u2261",
|
|
5866
|
+
le: "\u2264",
|
|
5867
|
+
ge: "\u2265",
|
|
5868
|
+
sub: "\u2282",
|
|
5869
|
+
sup: "\u2283",
|
|
5870
|
+
nsub: "\u2284",
|
|
5871
|
+
sube: "\u2286",
|
|
5872
|
+
supe: "\u2287",
|
|
5873
|
+
oplus: "\u2295",
|
|
5874
|
+
otimes: "\u2297",
|
|
5875
|
+
perp: "\u22A5",
|
|
5876
|
+
sdot: "\u22C5",
|
|
5877
|
+
lceil: "\u2308",
|
|
5878
|
+
rceil: "\u2309",
|
|
5879
|
+
lfloor: "\u230A",
|
|
5880
|
+
rfloor: "\u230B",
|
|
5881
|
+
lang: "\u2329",
|
|
5882
|
+
rang: "\u232A",
|
|
5883
|
+
loz: "\u25CA",
|
|
5884
|
+
spades: "\u2660",
|
|
5885
|
+
clubs: "\u2663",
|
|
5886
|
+
hearts: "\u2665",
|
|
5887
|
+
diams: "\u2666"
|
|
5888
|
+
};
|
|
5889
|
+
var hexNumber = /^[\da-fA-F]+$/;
|
|
5890
|
+
var decimalNumber = /^\d+$/;
|
|
5891
|
+
var acornJsxMap = /* @__PURE__ */ new WeakMap();
|
|
5892
|
+
function getJsxTokens(acorn) {
|
|
5893
|
+
acorn = acorn.Parser.acorn || acorn;
|
|
5894
|
+
let acornJsx2 = acornJsxMap.get(acorn);
|
|
5895
|
+
if (!acornJsx2) {
|
|
5896
|
+
const tt = acorn.tokTypes;
|
|
5897
|
+
const TokContext3 = acorn.TokContext;
|
|
5898
|
+
const TokenType3 = acorn.TokenType;
|
|
5899
|
+
const tc_oTag = new TokContext3("<tag", false);
|
|
5900
|
+
const tc_cTag = new TokContext3("</tag", false);
|
|
5901
|
+
const tc_expr = new TokContext3("<tag>...</tag>", true, true);
|
|
5902
|
+
const tokContexts = {
|
|
5903
|
+
tc_oTag,
|
|
5904
|
+
tc_cTag,
|
|
5905
|
+
tc_expr
|
|
5906
|
+
};
|
|
5907
|
+
const tokTypes = {
|
|
5908
|
+
jsxName: new TokenType3("jsxName"),
|
|
5909
|
+
jsxText: new TokenType3("jsxText", { beforeExpr: true }),
|
|
5910
|
+
jsxTagStart: new TokenType3("jsxTagStart", { startsExpr: true }),
|
|
5911
|
+
jsxTagEnd: new TokenType3("jsxTagEnd")
|
|
5912
|
+
};
|
|
5913
|
+
tokTypes.jsxTagStart.updateContext = function() {
|
|
5914
|
+
this.context.push(tc_expr);
|
|
5915
|
+
this.context.push(tc_oTag);
|
|
5916
|
+
this.exprAllowed = false;
|
|
5917
|
+
};
|
|
5918
|
+
tokTypes.jsxTagEnd.updateContext = function(prevType) {
|
|
5919
|
+
let out = this.context.pop();
|
|
5920
|
+
if (out === tc_oTag && prevType === tt.slash || out === tc_cTag) {
|
|
5921
|
+
this.context.pop();
|
|
5922
|
+
this.exprAllowed = this.curContext() === tc_expr;
|
|
5923
|
+
} else {
|
|
5924
|
+
this.exprAllowed = true;
|
|
5925
|
+
}
|
|
5926
|
+
};
|
|
5927
|
+
acornJsx2 = { tokContexts, tokTypes };
|
|
5928
|
+
acornJsxMap.set(acorn, acornJsx2);
|
|
5929
|
+
}
|
|
5930
|
+
return acornJsx2;
|
|
5931
|
+
}
|
|
5932
|
+
function getQualifiedJSXName(object) {
|
|
5933
|
+
if (!object)
|
|
5934
|
+
return object;
|
|
5935
|
+
if (object.type === "JSXIdentifier")
|
|
5936
|
+
return object.name;
|
|
5937
|
+
if (object.type === "JSXNamespacedName")
|
|
5938
|
+
return object.namespace.name + ":" + object.name.name;
|
|
5939
|
+
if (object.type === "JSXMemberExpression")
|
|
5940
|
+
return getQualifiedJSXName(object.object) + "." + getQualifiedJSXName(object.property);
|
|
5941
|
+
}
|
|
5942
|
+
function acornJsx(options) {
|
|
5943
|
+
options = options || {};
|
|
5944
|
+
return function(Parser3) {
|
|
5945
|
+
return plugin({
|
|
5946
|
+
allowNamespaces: options.allowNamespaces !== false,
|
|
5947
|
+
allowNamespacedObjects: !!options.allowNamespacedObjects
|
|
5948
|
+
}, Parser3);
|
|
5949
|
+
};
|
|
5950
|
+
}
|
|
5951
|
+
function plugin(options, Parser3) {
|
|
5952
|
+
const acorn = Parser3.acorn || { tokTypes: tt, TokContext, TokenType, isNewLine: isNewLine2, isIdentifierStart: isIdentifierStart2, isIdentifierChar: isIdentifierChar2, tokContexts };
|
|
5953
|
+
const acornJsx2 = getJsxTokens(acorn);
|
|
5954
|
+
const tt = acorn.tokTypes;
|
|
5955
|
+
const tok = acornJsx2.tokTypes;
|
|
5956
|
+
const tokContexts = acorn.tokContexts;
|
|
5957
|
+
const tc_oTag = acornJsx2.tokContexts.tc_oTag;
|
|
5958
|
+
const tc_cTag = acornJsx2.tokContexts.tc_cTag;
|
|
5959
|
+
const tc_expr = acornJsx2.tokContexts.tc_expr;
|
|
5960
|
+
const isNewLine2 = acorn.isNewLine;
|
|
5961
|
+
const isIdentifierStart2 = acorn.isIdentifierStart;
|
|
5962
|
+
const isIdentifierChar2 = acorn.isIdentifierChar;
|
|
5963
|
+
return class extends Parser3 {
|
|
5964
|
+
// Expose actual `tokTypes` and `tokContexts` to other plugins.
|
|
5965
|
+
static get acornJsx() {
|
|
5966
|
+
return acornJsx2;
|
|
5967
|
+
}
|
|
5968
|
+
// Reads inline JSX contents token.
|
|
5969
|
+
jsx_readToken() {
|
|
5970
|
+
let out = "", chunkStart = this.pos;
|
|
5971
|
+
for (; ; ) {
|
|
5972
|
+
if (this.pos >= this.input.length)
|
|
5973
|
+
this.raise(this.start, "Unterminated JSX contents");
|
|
5974
|
+
let ch = this.input.charCodeAt(this.pos);
|
|
5975
|
+
switch (ch) {
|
|
5976
|
+
case 60:
|
|
5977
|
+
// '<'
|
|
5978
|
+
case 123:
|
|
5979
|
+
if (this.pos === this.start) {
|
|
5980
|
+
if (ch === 60 && this.exprAllowed) {
|
|
5981
|
+
++this.pos;
|
|
5982
|
+
return this.finishToken(tok.jsxTagStart);
|
|
5983
|
+
}
|
|
5984
|
+
return this.getTokenFromCode(ch);
|
|
5985
|
+
}
|
|
5986
|
+
out += this.input.slice(chunkStart, this.pos);
|
|
5987
|
+
return this.finishToken(tok.jsxText, out);
|
|
5988
|
+
case 38:
|
|
5989
|
+
out += this.input.slice(chunkStart, this.pos);
|
|
5990
|
+
out += this.jsx_readEntity();
|
|
5991
|
+
chunkStart = this.pos;
|
|
5992
|
+
break;
|
|
5993
|
+
case 62:
|
|
5994
|
+
// '>'
|
|
5995
|
+
case 125:
|
|
5996
|
+
this.raise(
|
|
5997
|
+
this.pos,
|
|
5998
|
+
"Unexpected token `" + this.input[this.pos] + "`. Did you mean `" + (ch === 62 ? ">" : "}") + '` or `{"' + this.input[this.pos] + '"}`?'
|
|
5999
|
+
);
|
|
6000
|
+
default:
|
|
6001
|
+
if (isNewLine2(ch)) {
|
|
6002
|
+
out += this.input.slice(chunkStart, this.pos);
|
|
6003
|
+
out += this.jsx_readNewLine(true);
|
|
6004
|
+
chunkStart = this.pos;
|
|
6005
|
+
} else {
|
|
6006
|
+
++this.pos;
|
|
6007
|
+
}
|
|
6008
|
+
}
|
|
6009
|
+
}
|
|
6010
|
+
}
|
|
6011
|
+
jsx_readNewLine(normalizeCRLF) {
|
|
6012
|
+
let ch = this.input.charCodeAt(this.pos);
|
|
6013
|
+
let out;
|
|
6014
|
+
++this.pos;
|
|
6015
|
+
if (ch === 13 && this.input.charCodeAt(this.pos) === 10) {
|
|
6016
|
+
++this.pos;
|
|
6017
|
+
out = normalizeCRLF ? "\n" : "\r\n";
|
|
6018
|
+
} else {
|
|
6019
|
+
out = String.fromCharCode(ch);
|
|
6020
|
+
}
|
|
6021
|
+
if (this.options.locations) {
|
|
6022
|
+
++this.curLine;
|
|
6023
|
+
this.lineStart = this.pos;
|
|
6024
|
+
}
|
|
6025
|
+
return out;
|
|
6026
|
+
}
|
|
6027
|
+
jsx_readString(quote) {
|
|
6028
|
+
let out = "", chunkStart = ++this.pos;
|
|
6029
|
+
for (; ; ) {
|
|
6030
|
+
if (this.pos >= this.input.length)
|
|
6031
|
+
this.raise(this.start, "Unterminated string constant");
|
|
6032
|
+
let ch = this.input.charCodeAt(this.pos);
|
|
6033
|
+
if (ch === quote) break;
|
|
6034
|
+
if (ch === 38) {
|
|
6035
|
+
out += this.input.slice(chunkStart, this.pos);
|
|
6036
|
+
out += this.jsx_readEntity();
|
|
6037
|
+
chunkStart = this.pos;
|
|
6038
|
+
} else if (isNewLine2(ch)) {
|
|
6039
|
+
out += this.input.slice(chunkStart, this.pos);
|
|
6040
|
+
out += this.jsx_readNewLine(false);
|
|
6041
|
+
chunkStart = this.pos;
|
|
6042
|
+
} else {
|
|
6043
|
+
++this.pos;
|
|
6044
|
+
}
|
|
6045
|
+
}
|
|
6046
|
+
out += this.input.slice(chunkStart, this.pos++);
|
|
6047
|
+
return this.finishToken(tt.string, out);
|
|
6048
|
+
}
|
|
6049
|
+
jsx_readEntity() {
|
|
6050
|
+
let str = "", count = 0, entity;
|
|
6051
|
+
let ch = this.input[this.pos];
|
|
6052
|
+
if (ch !== "&")
|
|
6053
|
+
this.raise(this.pos, "Entity must start with an ampersand");
|
|
6054
|
+
let startPos = ++this.pos;
|
|
6055
|
+
while (this.pos < this.input.length && count++ < 10) {
|
|
6056
|
+
ch = this.input[this.pos++];
|
|
6057
|
+
if (ch === ";") {
|
|
6058
|
+
if (str[0] === "#") {
|
|
6059
|
+
if (str[1] === "x") {
|
|
6060
|
+
str = str.substr(2);
|
|
6061
|
+
if (hexNumber.test(str))
|
|
6062
|
+
entity = String.fromCharCode(parseInt(str, 16));
|
|
6063
|
+
} else {
|
|
6064
|
+
str = str.substr(1);
|
|
6065
|
+
if (decimalNumber.test(str))
|
|
6066
|
+
entity = String.fromCharCode(parseInt(str, 10));
|
|
6067
|
+
}
|
|
6068
|
+
} else {
|
|
6069
|
+
entity = XHTMLEntities[str];
|
|
6070
|
+
}
|
|
6071
|
+
break;
|
|
6072
|
+
}
|
|
6073
|
+
str += ch;
|
|
6074
|
+
}
|
|
6075
|
+
if (!entity) {
|
|
6076
|
+
this.pos = startPos;
|
|
6077
|
+
return "&";
|
|
6078
|
+
}
|
|
6079
|
+
return entity;
|
|
6080
|
+
}
|
|
6081
|
+
// Read a JSX identifier (valid tag or attribute name).
|
|
6082
|
+
//
|
|
6083
|
+
// Optimized version since JSX identifiers can't contain
|
|
6084
|
+
// escape characters and so can be read as single slice.
|
|
6085
|
+
// Also assumes that first character was already checked
|
|
6086
|
+
// by isIdentifierStart in readToken.
|
|
6087
|
+
jsx_readWord() {
|
|
6088
|
+
let ch, start = this.pos;
|
|
6089
|
+
do {
|
|
6090
|
+
ch = this.input.charCodeAt(++this.pos);
|
|
6091
|
+
} while (isIdentifierChar2(ch) || ch === 45);
|
|
6092
|
+
return this.finishToken(tok.jsxName, this.input.slice(start, this.pos));
|
|
6093
|
+
}
|
|
6094
|
+
// Parse next token as JSX identifier
|
|
6095
|
+
jsx_parseIdentifier() {
|
|
6096
|
+
let node = this.startNode();
|
|
6097
|
+
if (this.type === tok.jsxName)
|
|
6098
|
+
node.name = this.value;
|
|
6099
|
+
else if (this.type.keyword)
|
|
6100
|
+
node.name = this.type.keyword;
|
|
6101
|
+
else
|
|
6102
|
+
this.unexpected();
|
|
6103
|
+
this.next();
|
|
6104
|
+
return this.finishNode(node, "JSXIdentifier");
|
|
6105
|
+
}
|
|
6106
|
+
// Parse namespaced identifier.
|
|
6107
|
+
jsx_parseNamespacedName() {
|
|
6108
|
+
let startPos = this.start, startLoc = this.startLoc;
|
|
6109
|
+
let name = this.jsx_parseIdentifier();
|
|
6110
|
+
if (!options.allowNamespaces || !this.eat(tt.colon)) return name;
|
|
6111
|
+
var node = this.startNodeAt(startPos, startLoc);
|
|
6112
|
+
node.namespace = name;
|
|
6113
|
+
node.name = this.jsx_parseIdentifier();
|
|
6114
|
+
return this.finishNode(node, "JSXNamespacedName");
|
|
6115
|
+
}
|
|
6116
|
+
// Parses element name in any form - namespaced, member
|
|
6117
|
+
// or single identifier.
|
|
6118
|
+
jsx_parseElementName() {
|
|
6119
|
+
if (this.type === tok.jsxTagEnd) return "";
|
|
6120
|
+
let startPos = this.start, startLoc = this.startLoc;
|
|
6121
|
+
let node = this.jsx_parseNamespacedName();
|
|
6122
|
+
if (this.type === tt.dot && node.type === "JSXNamespacedName" && !options.allowNamespacedObjects) {
|
|
6123
|
+
this.unexpected();
|
|
6124
|
+
}
|
|
6125
|
+
while (this.eat(tt.dot)) {
|
|
6126
|
+
let newNode = this.startNodeAt(startPos, startLoc);
|
|
6127
|
+
newNode.object = node;
|
|
6128
|
+
newNode.property = this.jsx_parseIdentifier();
|
|
6129
|
+
node = this.finishNode(newNode, "JSXMemberExpression");
|
|
6130
|
+
}
|
|
6131
|
+
return node;
|
|
6132
|
+
}
|
|
6133
|
+
// Parses any type of JSX attribute value.
|
|
6134
|
+
jsx_parseAttributeValue() {
|
|
6135
|
+
switch (this.type) {
|
|
6136
|
+
case tt.braceL:
|
|
6137
|
+
let node = this.jsx_parseExpressionContainer();
|
|
6138
|
+
if (node.expression.type === "JSXEmptyExpression")
|
|
6139
|
+
this.raise(node.start, "JSX attributes must only be assigned a non-empty expression");
|
|
6140
|
+
return node;
|
|
6141
|
+
case tok.jsxTagStart:
|
|
6142
|
+
case tt.string:
|
|
6143
|
+
return this.parseExprAtom();
|
|
6144
|
+
default:
|
|
6145
|
+
this.raise(this.start, "JSX value should be either an expression or a quoted JSX text");
|
|
6146
|
+
}
|
|
6147
|
+
}
|
|
6148
|
+
// JSXEmptyExpression is unique type since it doesn't actually parse anything,
|
|
6149
|
+
// and so it should start at the end of last read token (left brace) and finish
|
|
6150
|
+
// at the beginning of the next one (right brace).
|
|
6151
|
+
jsx_parseEmptyExpression() {
|
|
6152
|
+
let node = this.startNodeAt(this.lastTokEnd, this.lastTokEndLoc);
|
|
6153
|
+
return this.finishNodeAt(node, "JSXEmptyExpression", this.start, this.startLoc);
|
|
6154
|
+
}
|
|
6155
|
+
// Parses JSX expression enclosed into curly brackets.
|
|
6156
|
+
jsx_parseExpressionContainer() {
|
|
6157
|
+
let node = this.startNode();
|
|
6158
|
+
this.next();
|
|
6159
|
+
node.expression = this.type === tt.braceR ? this.jsx_parseEmptyExpression() : this.parseExpression();
|
|
6160
|
+
this.expect(tt.braceR);
|
|
6161
|
+
return this.finishNode(node, "JSXExpressionContainer");
|
|
6162
|
+
}
|
|
6163
|
+
// Parses following JSX attribute name-value pair.
|
|
6164
|
+
jsx_parseAttribute() {
|
|
6165
|
+
let node = this.startNode();
|
|
6166
|
+
if (this.eat(tt.braceL)) {
|
|
6167
|
+
this.expect(tt.ellipsis);
|
|
6168
|
+
node.argument = this.parseMaybeAssign();
|
|
6169
|
+
this.expect(tt.braceR);
|
|
6170
|
+
return this.finishNode(node, "JSXSpreadAttribute");
|
|
6171
|
+
}
|
|
6172
|
+
node.name = this.jsx_parseNamespacedName();
|
|
6173
|
+
node.value = this.eat(tt.eq) ? this.jsx_parseAttributeValue() : null;
|
|
6174
|
+
return this.finishNode(node, "JSXAttribute");
|
|
6175
|
+
}
|
|
6176
|
+
// Parses JSX opening tag starting after '<'.
|
|
6177
|
+
jsx_parseOpeningElementAt(startPos, startLoc) {
|
|
6178
|
+
let node = this.startNodeAt(startPos, startLoc);
|
|
6179
|
+
node.attributes = [];
|
|
6180
|
+
let nodeName = this.jsx_parseElementName();
|
|
6181
|
+
if (nodeName) node.name = nodeName;
|
|
6182
|
+
while (this.type !== tt.slash && this.type !== tok.jsxTagEnd)
|
|
6183
|
+
node.attributes.push(this.jsx_parseAttribute());
|
|
6184
|
+
node.selfClosing = this.eat(tt.slash);
|
|
6185
|
+
this.expect(tok.jsxTagEnd);
|
|
6186
|
+
return this.finishNode(node, nodeName ? "JSXOpeningElement" : "JSXOpeningFragment");
|
|
6187
|
+
}
|
|
6188
|
+
// Parses JSX closing tag starting after '</'.
|
|
6189
|
+
jsx_parseClosingElementAt(startPos, startLoc) {
|
|
6190
|
+
let node = this.startNodeAt(startPos, startLoc);
|
|
6191
|
+
let nodeName = this.jsx_parseElementName();
|
|
6192
|
+
if (nodeName) node.name = nodeName;
|
|
6193
|
+
this.expect(tok.jsxTagEnd);
|
|
6194
|
+
return this.finishNode(node, nodeName ? "JSXClosingElement" : "JSXClosingFragment");
|
|
6195
|
+
}
|
|
6196
|
+
// Parses entire JSX element, including it's opening tag
|
|
6197
|
+
// (starting after '<'), attributes, contents and closing tag.
|
|
6198
|
+
jsx_parseElementAt(startPos, startLoc) {
|
|
6199
|
+
let node = this.startNodeAt(startPos, startLoc);
|
|
6200
|
+
let children = [];
|
|
6201
|
+
let openingElement = this.jsx_parseOpeningElementAt(startPos, startLoc);
|
|
6202
|
+
let closingElement = null;
|
|
6203
|
+
if (!openingElement.selfClosing) {
|
|
6204
|
+
contents: for (; ; ) {
|
|
6205
|
+
switch (this.type) {
|
|
6206
|
+
case tok.jsxTagStart:
|
|
6207
|
+
startPos = this.start;
|
|
6208
|
+
startLoc = this.startLoc;
|
|
6209
|
+
this.next();
|
|
6210
|
+
if (this.eat(tt.slash)) {
|
|
6211
|
+
closingElement = this.jsx_parseClosingElementAt(startPos, startLoc);
|
|
6212
|
+
break contents;
|
|
6213
|
+
}
|
|
6214
|
+
children.push(this.jsx_parseElementAt(startPos, startLoc));
|
|
6215
|
+
break;
|
|
6216
|
+
case tok.jsxText:
|
|
6217
|
+
children.push(this.parseExprAtom());
|
|
6218
|
+
break;
|
|
6219
|
+
case tt.braceL:
|
|
6220
|
+
children.push(this.jsx_parseExpressionContainer());
|
|
6221
|
+
break;
|
|
6222
|
+
default:
|
|
6223
|
+
this.unexpected();
|
|
6224
|
+
}
|
|
6225
|
+
}
|
|
6226
|
+
if (getQualifiedJSXName(closingElement.name) !== getQualifiedJSXName(openingElement.name)) {
|
|
6227
|
+
this.raise(
|
|
6228
|
+
closingElement.start,
|
|
6229
|
+
"Expected corresponding JSX closing tag for <" + getQualifiedJSXName(openingElement.name) + ">"
|
|
6230
|
+
);
|
|
6231
|
+
}
|
|
6232
|
+
}
|
|
6233
|
+
let fragmentOrElement = openingElement.name ? "Element" : "Fragment";
|
|
6234
|
+
node["opening" + fragmentOrElement] = openingElement;
|
|
6235
|
+
node["closing" + fragmentOrElement] = closingElement;
|
|
6236
|
+
node.children = children;
|
|
6237
|
+
if (this.type === tt.relational && this.value === "<") {
|
|
6238
|
+
this.raise(this.start, "Adjacent JSX elements must be wrapped in an enclosing tag");
|
|
6239
|
+
}
|
|
6240
|
+
return this.finishNode(node, "JSX" + fragmentOrElement);
|
|
6241
|
+
}
|
|
6242
|
+
// Parse JSX text
|
|
6243
|
+
jsx_parseText() {
|
|
6244
|
+
let node = this.parseLiteral(this.value);
|
|
6245
|
+
node.type = "JSXText";
|
|
6246
|
+
return node;
|
|
6247
|
+
}
|
|
6248
|
+
// Parses entire JSX element from current position.
|
|
6249
|
+
jsx_parseElement() {
|
|
6250
|
+
let startPos = this.start, startLoc = this.startLoc;
|
|
6251
|
+
this.next();
|
|
6252
|
+
return this.jsx_parseElementAt(startPos, startLoc);
|
|
6253
|
+
}
|
|
6254
|
+
parseExprAtom(refShortHandDefaultPos) {
|
|
6255
|
+
if (this.type === tok.jsxText)
|
|
6256
|
+
return this.jsx_parseText();
|
|
6257
|
+
else if (this.type === tok.jsxTagStart)
|
|
6258
|
+
return this.jsx_parseElement();
|
|
6259
|
+
else
|
|
6260
|
+
return super.parseExprAtom(refShortHandDefaultPos);
|
|
6261
|
+
}
|
|
6262
|
+
readToken(code) {
|
|
6263
|
+
let context = this.curContext();
|
|
6264
|
+
if (context === tc_expr) return this.jsx_readToken();
|
|
6265
|
+
if (context === tc_oTag || context === tc_cTag) {
|
|
6266
|
+
if (isIdentifierStart2(code)) return this.jsx_readWord();
|
|
6267
|
+
if (code == 62) {
|
|
6268
|
+
++this.pos;
|
|
6269
|
+
return this.finishToken(tok.jsxTagEnd);
|
|
6270
|
+
}
|
|
6271
|
+
if ((code === 34 || code === 39) && context == tc_oTag)
|
|
6272
|
+
return this.jsx_readString(code);
|
|
6273
|
+
}
|
|
6274
|
+
if (code === 60 && this.exprAllowed && this.input.charCodeAt(this.pos + 1) !== 33) {
|
|
6275
|
+
++this.pos;
|
|
6276
|
+
return this.finishToken(tok.jsxTagStart);
|
|
6277
|
+
}
|
|
6278
|
+
return super.readToken(code);
|
|
6279
|
+
}
|
|
6280
|
+
updateContext(prevType) {
|
|
6281
|
+
if (this.type == tt.braceL) {
|
|
6282
|
+
var curContext = this.curContext();
|
|
6283
|
+
if (curContext == tc_oTag) this.context.push(tokContexts.b_expr);
|
|
6284
|
+
else if (curContext == tc_expr) this.context.push(tokContexts.b_tmpl);
|
|
6285
|
+
else super.updateContext(prevType);
|
|
6286
|
+
this.exprAllowed = true;
|
|
6287
|
+
} else if (this.type === tt.slash && prevType === tok.jsxTagStart) {
|
|
6288
|
+
this.context.length -= 2;
|
|
6289
|
+
this.context.push(tc_cTag);
|
|
6290
|
+
this.exprAllowed = false;
|
|
6291
|
+
} else {
|
|
6292
|
+
return super.updateContext(prevType);
|
|
6293
|
+
}
|
|
6294
|
+
}
|
|
6295
|
+
};
|
|
6296
|
+
}
|
|
6297
|
+
var JSXParser = Parser.extend(acornJsx());
|
|
6298
|
+
function jsxParse(input, options) {
|
|
6299
|
+
return JSXParser.parse(input, options);
|
|
5636
6300
|
}
|
|
5637
6301
|
|
|
5638
6302
|
// src/index.js
|
|
@@ -5645,14 +6309,14 @@ function containsModuleSyntax(code) {
|
|
|
5645
6309
|
}
|
|
5646
6310
|
return false;
|
|
5647
6311
|
}
|
|
5648
|
-
function
|
|
6312
|
+
function parse3(code, options = {}) {
|
|
5649
6313
|
var _a;
|
|
5650
6314
|
let sourceType = options.sourceType || "script";
|
|
5651
6315
|
if (!options.sourceType && containsModuleSyntax(code)) {
|
|
5652
6316
|
sourceType = "module";
|
|
5653
6317
|
}
|
|
5654
6318
|
try {
|
|
5655
|
-
return
|
|
6319
|
+
return jsxParse(code, {
|
|
5656
6320
|
ecmaVersion: 2022,
|
|
5657
6321
|
// Support ES2022 features (including top-level await)
|
|
5658
6322
|
sourceType,
|
|
@@ -5682,7 +6346,7 @@ var WangValidator = class {
|
|
|
5682
6346
|
validate(code, options = {}) {
|
|
5683
6347
|
var _a, _b;
|
|
5684
6348
|
try {
|
|
5685
|
-
const ast =
|
|
6349
|
+
const ast = parse3(code);
|
|
5686
6350
|
return {
|
|
5687
6351
|
valid: true,
|
|
5688
6352
|
ast: options.includeAST ? ast : void 0
|