jslike 1.5.0 → 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/interpreter/interpreter.js +285 -0
- package/dist/esm/parser.js +781 -3
- package/dist/esm/runtime/builtins.js +14 -0
- package/dist/index.cjs +913 -7
- package/dist/index.d.cts +1044 -11
- package/dist/index.d.ts +1044 -11
- package/dist/index.js +913 -7
- package/dist/validator/index.cjs +669 -5
- package/dist/validator/index.js +669 -5
- package/package.json +5 -2
package/dist/index.cjs
CHANGED
|
@@ -28,7 +28,7 @@ __export(src_exports, {
|
|
|
28
28
|
createEnvironment: () => createEnvironment,
|
|
29
29
|
execute: () => execute,
|
|
30
30
|
isTopLevelAwait: () => isTopLevelAwait,
|
|
31
|
-
parse: () =>
|
|
31
|
+
parse: () => parse3
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(src_exports);
|
|
34
34
|
|
|
@@ -5640,8 +5640,672 @@ Parser.acorn = {
|
|
|
5640
5640
|
lineBreakG,
|
|
5641
5641
|
nonASCIIwhitespace
|
|
5642
5642
|
};
|
|
5643
|
-
|
|
5644
|
-
|
|
5643
|
+
var XHTMLEntities = {
|
|
5644
|
+
quot: '"',
|
|
5645
|
+
amp: "&",
|
|
5646
|
+
apos: "'",
|
|
5647
|
+
lt: "<",
|
|
5648
|
+
gt: ">",
|
|
5649
|
+
nbsp: "\xA0",
|
|
5650
|
+
iexcl: "\xA1",
|
|
5651
|
+
cent: "\xA2",
|
|
5652
|
+
pound: "\xA3",
|
|
5653
|
+
curren: "\xA4",
|
|
5654
|
+
yen: "\xA5",
|
|
5655
|
+
brvbar: "\xA6",
|
|
5656
|
+
sect: "\xA7",
|
|
5657
|
+
uml: "\xA8",
|
|
5658
|
+
copy: "\xA9",
|
|
5659
|
+
ordf: "\xAA",
|
|
5660
|
+
laquo: "\xAB",
|
|
5661
|
+
not: "\xAC",
|
|
5662
|
+
shy: "\xAD",
|
|
5663
|
+
reg: "\xAE",
|
|
5664
|
+
macr: "\xAF",
|
|
5665
|
+
deg: "\xB0",
|
|
5666
|
+
plusmn: "\xB1",
|
|
5667
|
+
sup2: "\xB2",
|
|
5668
|
+
sup3: "\xB3",
|
|
5669
|
+
acute: "\xB4",
|
|
5670
|
+
micro: "\xB5",
|
|
5671
|
+
para: "\xB6",
|
|
5672
|
+
middot: "\xB7",
|
|
5673
|
+
cedil: "\xB8",
|
|
5674
|
+
sup1: "\xB9",
|
|
5675
|
+
ordm: "\xBA",
|
|
5676
|
+
raquo: "\xBB",
|
|
5677
|
+
frac14: "\xBC",
|
|
5678
|
+
frac12: "\xBD",
|
|
5679
|
+
frac34: "\xBE",
|
|
5680
|
+
iquest: "\xBF",
|
|
5681
|
+
Agrave: "\xC0",
|
|
5682
|
+
Aacute: "\xC1",
|
|
5683
|
+
Acirc: "\xC2",
|
|
5684
|
+
Atilde: "\xC3",
|
|
5685
|
+
Auml: "\xC4",
|
|
5686
|
+
Aring: "\xC5",
|
|
5687
|
+
AElig: "\xC6",
|
|
5688
|
+
Ccedil: "\xC7",
|
|
5689
|
+
Egrave: "\xC8",
|
|
5690
|
+
Eacute: "\xC9",
|
|
5691
|
+
Ecirc: "\xCA",
|
|
5692
|
+
Euml: "\xCB",
|
|
5693
|
+
Igrave: "\xCC",
|
|
5694
|
+
Iacute: "\xCD",
|
|
5695
|
+
Icirc: "\xCE",
|
|
5696
|
+
Iuml: "\xCF",
|
|
5697
|
+
ETH: "\xD0",
|
|
5698
|
+
Ntilde: "\xD1",
|
|
5699
|
+
Ograve: "\xD2",
|
|
5700
|
+
Oacute: "\xD3",
|
|
5701
|
+
Ocirc: "\xD4",
|
|
5702
|
+
Otilde: "\xD5",
|
|
5703
|
+
Ouml: "\xD6",
|
|
5704
|
+
times: "\xD7",
|
|
5705
|
+
Oslash: "\xD8",
|
|
5706
|
+
Ugrave: "\xD9",
|
|
5707
|
+
Uacute: "\xDA",
|
|
5708
|
+
Ucirc: "\xDB",
|
|
5709
|
+
Uuml: "\xDC",
|
|
5710
|
+
Yacute: "\xDD",
|
|
5711
|
+
THORN: "\xDE",
|
|
5712
|
+
szlig: "\xDF",
|
|
5713
|
+
agrave: "\xE0",
|
|
5714
|
+
aacute: "\xE1",
|
|
5715
|
+
acirc: "\xE2",
|
|
5716
|
+
atilde: "\xE3",
|
|
5717
|
+
auml: "\xE4",
|
|
5718
|
+
aring: "\xE5",
|
|
5719
|
+
aelig: "\xE6",
|
|
5720
|
+
ccedil: "\xE7",
|
|
5721
|
+
egrave: "\xE8",
|
|
5722
|
+
eacute: "\xE9",
|
|
5723
|
+
ecirc: "\xEA",
|
|
5724
|
+
euml: "\xEB",
|
|
5725
|
+
igrave: "\xEC",
|
|
5726
|
+
iacute: "\xED",
|
|
5727
|
+
icirc: "\xEE",
|
|
5728
|
+
iuml: "\xEF",
|
|
5729
|
+
eth: "\xF0",
|
|
5730
|
+
ntilde: "\xF1",
|
|
5731
|
+
ograve: "\xF2",
|
|
5732
|
+
oacute: "\xF3",
|
|
5733
|
+
ocirc: "\xF4",
|
|
5734
|
+
otilde: "\xF5",
|
|
5735
|
+
ouml: "\xF6",
|
|
5736
|
+
divide: "\xF7",
|
|
5737
|
+
oslash: "\xF8",
|
|
5738
|
+
ugrave: "\xF9",
|
|
5739
|
+
uacute: "\xFA",
|
|
5740
|
+
ucirc: "\xFB",
|
|
5741
|
+
uuml: "\xFC",
|
|
5742
|
+
yacute: "\xFD",
|
|
5743
|
+
thorn: "\xFE",
|
|
5744
|
+
yuml: "\xFF",
|
|
5745
|
+
OElig: "\u0152",
|
|
5746
|
+
oelig: "\u0153",
|
|
5747
|
+
Scaron: "\u0160",
|
|
5748
|
+
scaron: "\u0161",
|
|
5749
|
+
Yuml: "\u0178",
|
|
5750
|
+
fnof: "\u0192",
|
|
5751
|
+
circ: "\u02C6",
|
|
5752
|
+
tilde: "\u02DC",
|
|
5753
|
+
Alpha: "\u0391",
|
|
5754
|
+
Beta: "\u0392",
|
|
5755
|
+
Gamma: "\u0393",
|
|
5756
|
+
Delta: "\u0394",
|
|
5757
|
+
Epsilon: "\u0395",
|
|
5758
|
+
Zeta: "\u0396",
|
|
5759
|
+
Eta: "\u0397",
|
|
5760
|
+
Theta: "\u0398",
|
|
5761
|
+
Iota: "\u0399",
|
|
5762
|
+
Kappa: "\u039A",
|
|
5763
|
+
Lambda: "\u039B",
|
|
5764
|
+
Mu: "\u039C",
|
|
5765
|
+
Nu: "\u039D",
|
|
5766
|
+
Xi: "\u039E",
|
|
5767
|
+
Omicron: "\u039F",
|
|
5768
|
+
Pi: "\u03A0",
|
|
5769
|
+
Rho: "\u03A1",
|
|
5770
|
+
Sigma: "\u03A3",
|
|
5771
|
+
Tau: "\u03A4",
|
|
5772
|
+
Upsilon: "\u03A5",
|
|
5773
|
+
Phi: "\u03A6",
|
|
5774
|
+
Chi: "\u03A7",
|
|
5775
|
+
Psi: "\u03A8",
|
|
5776
|
+
Omega: "\u03A9",
|
|
5777
|
+
alpha: "\u03B1",
|
|
5778
|
+
beta: "\u03B2",
|
|
5779
|
+
gamma: "\u03B3",
|
|
5780
|
+
delta: "\u03B4",
|
|
5781
|
+
epsilon: "\u03B5",
|
|
5782
|
+
zeta: "\u03B6",
|
|
5783
|
+
eta: "\u03B7",
|
|
5784
|
+
theta: "\u03B8",
|
|
5785
|
+
iota: "\u03B9",
|
|
5786
|
+
kappa: "\u03BA",
|
|
5787
|
+
lambda: "\u03BB",
|
|
5788
|
+
mu: "\u03BC",
|
|
5789
|
+
nu: "\u03BD",
|
|
5790
|
+
xi: "\u03BE",
|
|
5791
|
+
omicron: "\u03BF",
|
|
5792
|
+
pi: "\u03C0",
|
|
5793
|
+
rho: "\u03C1",
|
|
5794
|
+
sigmaf: "\u03C2",
|
|
5795
|
+
sigma: "\u03C3",
|
|
5796
|
+
tau: "\u03C4",
|
|
5797
|
+
upsilon: "\u03C5",
|
|
5798
|
+
phi: "\u03C6",
|
|
5799
|
+
chi: "\u03C7",
|
|
5800
|
+
psi: "\u03C8",
|
|
5801
|
+
omega: "\u03C9",
|
|
5802
|
+
thetasym: "\u03D1",
|
|
5803
|
+
upsih: "\u03D2",
|
|
5804
|
+
piv: "\u03D6",
|
|
5805
|
+
ensp: "\u2002",
|
|
5806
|
+
emsp: "\u2003",
|
|
5807
|
+
thinsp: "\u2009",
|
|
5808
|
+
zwnj: "\u200C",
|
|
5809
|
+
zwj: "\u200D",
|
|
5810
|
+
lrm: "\u200E",
|
|
5811
|
+
rlm: "\u200F",
|
|
5812
|
+
ndash: "\u2013",
|
|
5813
|
+
mdash: "\u2014",
|
|
5814
|
+
lsquo: "\u2018",
|
|
5815
|
+
rsquo: "\u2019",
|
|
5816
|
+
sbquo: "\u201A",
|
|
5817
|
+
ldquo: "\u201C",
|
|
5818
|
+
rdquo: "\u201D",
|
|
5819
|
+
bdquo: "\u201E",
|
|
5820
|
+
dagger: "\u2020",
|
|
5821
|
+
Dagger: "\u2021",
|
|
5822
|
+
bull: "\u2022",
|
|
5823
|
+
hellip: "\u2026",
|
|
5824
|
+
permil: "\u2030",
|
|
5825
|
+
prime: "\u2032",
|
|
5826
|
+
Prime: "\u2033",
|
|
5827
|
+
lsaquo: "\u2039",
|
|
5828
|
+
rsaquo: "\u203A",
|
|
5829
|
+
oline: "\u203E",
|
|
5830
|
+
frasl: "\u2044",
|
|
5831
|
+
euro: "\u20AC",
|
|
5832
|
+
image: "\u2111",
|
|
5833
|
+
weierp: "\u2118",
|
|
5834
|
+
real: "\u211C",
|
|
5835
|
+
trade: "\u2122",
|
|
5836
|
+
alefsym: "\u2135",
|
|
5837
|
+
larr: "\u2190",
|
|
5838
|
+
uarr: "\u2191",
|
|
5839
|
+
rarr: "\u2192",
|
|
5840
|
+
darr: "\u2193",
|
|
5841
|
+
harr: "\u2194",
|
|
5842
|
+
crarr: "\u21B5",
|
|
5843
|
+
lArr: "\u21D0",
|
|
5844
|
+
uArr: "\u21D1",
|
|
5845
|
+
rArr: "\u21D2",
|
|
5846
|
+
dArr: "\u21D3",
|
|
5847
|
+
hArr: "\u21D4",
|
|
5848
|
+
forall: "\u2200",
|
|
5849
|
+
part: "\u2202",
|
|
5850
|
+
exist: "\u2203",
|
|
5851
|
+
empty: "\u2205",
|
|
5852
|
+
nabla: "\u2207",
|
|
5853
|
+
isin: "\u2208",
|
|
5854
|
+
notin: "\u2209",
|
|
5855
|
+
ni: "\u220B",
|
|
5856
|
+
prod: "\u220F",
|
|
5857
|
+
sum: "\u2211",
|
|
5858
|
+
minus: "\u2212",
|
|
5859
|
+
lowast: "\u2217",
|
|
5860
|
+
radic: "\u221A",
|
|
5861
|
+
prop: "\u221D",
|
|
5862
|
+
infin: "\u221E",
|
|
5863
|
+
ang: "\u2220",
|
|
5864
|
+
and: "\u2227",
|
|
5865
|
+
or: "\u2228",
|
|
5866
|
+
cap: "\u2229",
|
|
5867
|
+
cup: "\u222A",
|
|
5868
|
+
"int": "\u222B",
|
|
5869
|
+
there4: "\u2234",
|
|
5870
|
+
sim: "\u223C",
|
|
5871
|
+
cong: "\u2245",
|
|
5872
|
+
asymp: "\u2248",
|
|
5873
|
+
ne: "\u2260",
|
|
5874
|
+
equiv: "\u2261",
|
|
5875
|
+
le: "\u2264",
|
|
5876
|
+
ge: "\u2265",
|
|
5877
|
+
sub: "\u2282",
|
|
5878
|
+
sup: "\u2283",
|
|
5879
|
+
nsub: "\u2284",
|
|
5880
|
+
sube: "\u2286",
|
|
5881
|
+
supe: "\u2287",
|
|
5882
|
+
oplus: "\u2295",
|
|
5883
|
+
otimes: "\u2297",
|
|
5884
|
+
perp: "\u22A5",
|
|
5885
|
+
sdot: "\u22C5",
|
|
5886
|
+
lceil: "\u2308",
|
|
5887
|
+
rceil: "\u2309",
|
|
5888
|
+
lfloor: "\u230A",
|
|
5889
|
+
rfloor: "\u230B",
|
|
5890
|
+
lang: "\u2329",
|
|
5891
|
+
rang: "\u232A",
|
|
5892
|
+
loz: "\u25CA",
|
|
5893
|
+
spades: "\u2660",
|
|
5894
|
+
clubs: "\u2663",
|
|
5895
|
+
hearts: "\u2665",
|
|
5896
|
+
diams: "\u2666"
|
|
5897
|
+
};
|
|
5898
|
+
var hexNumber = /^[\da-fA-F]+$/;
|
|
5899
|
+
var decimalNumber = /^\d+$/;
|
|
5900
|
+
var acornJsxMap = /* @__PURE__ */ new WeakMap();
|
|
5901
|
+
function getJsxTokens(acorn) {
|
|
5902
|
+
acorn = acorn.Parser.acorn || acorn;
|
|
5903
|
+
let acornJsx2 = acornJsxMap.get(acorn);
|
|
5904
|
+
if (!acornJsx2) {
|
|
5905
|
+
const tt = acorn.tokTypes;
|
|
5906
|
+
const TokContext3 = acorn.TokContext;
|
|
5907
|
+
const TokenType3 = acorn.TokenType;
|
|
5908
|
+
const tc_oTag = new TokContext3("<tag", false);
|
|
5909
|
+
const tc_cTag = new TokContext3("</tag", false);
|
|
5910
|
+
const tc_expr = new TokContext3("<tag>...</tag>", true, true);
|
|
5911
|
+
const tokContexts = {
|
|
5912
|
+
tc_oTag,
|
|
5913
|
+
tc_cTag,
|
|
5914
|
+
tc_expr
|
|
5915
|
+
};
|
|
5916
|
+
const tokTypes = {
|
|
5917
|
+
jsxName: new TokenType3("jsxName"),
|
|
5918
|
+
jsxText: new TokenType3("jsxText", { beforeExpr: true }),
|
|
5919
|
+
jsxTagStart: new TokenType3("jsxTagStart", { startsExpr: true }),
|
|
5920
|
+
jsxTagEnd: new TokenType3("jsxTagEnd")
|
|
5921
|
+
};
|
|
5922
|
+
tokTypes.jsxTagStart.updateContext = function() {
|
|
5923
|
+
this.context.push(tc_expr);
|
|
5924
|
+
this.context.push(tc_oTag);
|
|
5925
|
+
this.exprAllowed = false;
|
|
5926
|
+
};
|
|
5927
|
+
tokTypes.jsxTagEnd.updateContext = function(prevType) {
|
|
5928
|
+
let out = this.context.pop();
|
|
5929
|
+
if (out === tc_oTag && prevType === tt.slash || out === tc_cTag) {
|
|
5930
|
+
this.context.pop();
|
|
5931
|
+
this.exprAllowed = this.curContext() === tc_expr;
|
|
5932
|
+
} else {
|
|
5933
|
+
this.exprAllowed = true;
|
|
5934
|
+
}
|
|
5935
|
+
};
|
|
5936
|
+
acornJsx2 = { tokContexts, tokTypes };
|
|
5937
|
+
acornJsxMap.set(acorn, acornJsx2);
|
|
5938
|
+
}
|
|
5939
|
+
return acornJsx2;
|
|
5940
|
+
}
|
|
5941
|
+
function getQualifiedJSXName(object) {
|
|
5942
|
+
if (!object)
|
|
5943
|
+
return object;
|
|
5944
|
+
if (object.type === "JSXIdentifier")
|
|
5945
|
+
return object.name;
|
|
5946
|
+
if (object.type === "JSXNamespacedName")
|
|
5947
|
+
return object.namespace.name + ":" + object.name.name;
|
|
5948
|
+
if (object.type === "JSXMemberExpression")
|
|
5949
|
+
return getQualifiedJSXName(object.object) + "." + getQualifiedJSXName(object.property);
|
|
5950
|
+
}
|
|
5951
|
+
function acornJsx(options) {
|
|
5952
|
+
options = options || {};
|
|
5953
|
+
return function(Parser3) {
|
|
5954
|
+
return plugin({
|
|
5955
|
+
allowNamespaces: options.allowNamespaces !== false,
|
|
5956
|
+
allowNamespacedObjects: !!options.allowNamespacedObjects
|
|
5957
|
+
}, Parser3);
|
|
5958
|
+
};
|
|
5959
|
+
}
|
|
5960
|
+
function plugin(options, Parser3) {
|
|
5961
|
+
const acorn = Parser3.acorn || { tokTypes: tt, TokContext, TokenType, isNewLine: isNewLine2, isIdentifierStart: isIdentifierStart2, isIdentifierChar: isIdentifierChar2, tokContexts };
|
|
5962
|
+
const acornJsx2 = getJsxTokens(acorn);
|
|
5963
|
+
const tt = acorn.tokTypes;
|
|
5964
|
+
const tok = acornJsx2.tokTypes;
|
|
5965
|
+
const tokContexts = acorn.tokContexts;
|
|
5966
|
+
const tc_oTag = acornJsx2.tokContexts.tc_oTag;
|
|
5967
|
+
const tc_cTag = acornJsx2.tokContexts.tc_cTag;
|
|
5968
|
+
const tc_expr = acornJsx2.tokContexts.tc_expr;
|
|
5969
|
+
const isNewLine2 = acorn.isNewLine;
|
|
5970
|
+
const isIdentifierStart2 = acorn.isIdentifierStart;
|
|
5971
|
+
const isIdentifierChar2 = acorn.isIdentifierChar;
|
|
5972
|
+
return class extends Parser3 {
|
|
5973
|
+
// Expose actual `tokTypes` and `tokContexts` to other plugins.
|
|
5974
|
+
static get acornJsx() {
|
|
5975
|
+
return acornJsx2;
|
|
5976
|
+
}
|
|
5977
|
+
// Reads inline JSX contents token.
|
|
5978
|
+
jsx_readToken() {
|
|
5979
|
+
let out = "", chunkStart = this.pos;
|
|
5980
|
+
for (; ; ) {
|
|
5981
|
+
if (this.pos >= this.input.length)
|
|
5982
|
+
this.raise(this.start, "Unterminated JSX contents");
|
|
5983
|
+
let ch = this.input.charCodeAt(this.pos);
|
|
5984
|
+
switch (ch) {
|
|
5985
|
+
case 60:
|
|
5986
|
+
// '<'
|
|
5987
|
+
case 123:
|
|
5988
|
+
if (this.pos === this.start) {
|
|
5989
|
+
if (ch === 60 && this.exprAllowed) {
|
|
5990
|
+
++this.pos;
|
|
5991
|
+
return this.finishToken(tok.jsxTagStart);
|
|
5992
|
+
}
|
|
5993
|
+
return this.getTokenFromCode(ch);
|
|
5994
|
+
}
|
|
5995
|
+
out += this.input.slice(chunkStart, this.pos);
|
|
5996
|
+
return this.finishToken(tok.jsxText, out);
|
|
5997
|
+
case 38:
|
|
5998
|
+
out += this.input.slice(chunkStart, this.pos);
|
|
5999
|
+
out += this.jsx_readEntity();
|
|
6000
|
+
chunkStart = this.pos;
|
|
6001
|
+
break;
|
|
6002
|
+
case 62:
|
|
6003
|
+
// '>'
|
|
6004
|
+
case 125:
|
|
6005
|
+
this.raise(
|
|
6006
|
+
this.pos,
|
|
6007
|
+
"Unexpected token `" + this.input[this.pos] + "`. Did you mean `" + (ch === 62 ? ">" : "}") + '` or `{"' + this.input[this.pos] + '"}`?'
|
|
6008
|
+
);
|
|
6009
|
+
default:
|
|
6010
|
+
if (isNewLine2(ch)) {
|
|
6011
|
+
out += this.input.slice(chunkStart, this.pos);
|
|
6012
|
+
out += this.jsx_readNewLine(true);
|
|
6013
|
+
chunkStart = this.pos;
|
|
6014
|
+
} else {
|
|
6015
|
+
++this.pos;
|
|
6016
|
+
}
|
|
6017
|
+
}
|
|
6018
|
+
}
|
|
6019
|
+
}
|
|
6020
|
+
jsx_readNewLine(normalizeCRLF) {
|
|
6021
|
+
let ch = this.input.charCodeAt(this.pos);
|
|
6022
|
+
let out;
|
|
6023
|
+
++this.pos;
|
|
6024
|
+
if (ch === 13 && this.input.charCodeAt(this.pos) === 10) {
|
|
6025
|
+
++this.pos;
|
|
6026
|
+
out = normalizeCRLF ? "\n" : "\r\n";
|
|
6027
|
+
} else {
|
|
6028
|
+
out = String.fromCharCode(ch);
|
|
6029
|
+
}
|
|
6030
|
+
if (this.options.locations) {
|
|
6031
|
+
++this.curLine;
|
|
6032
|
+
this.lineStart = this.pos;
|
|
6033
|
+
}
|
|
6034
|
+
return out;
|
|
6035
|
+
}
|
|
6036
|
+
jsx_readString(quote) {
|
|
6037
|
+
let out = "", chunkStart = ++this.pos;
|
|
6038
|
+
for (; ; ) {
|
|
6039
|
+
if (this.pos >= this.input.length)
|
|
6040
|
+
this.raise(this.start, "Unterminated string constant");
|
|
6041
|
+
let ch = this.input.charCodeAt(this.pos);
|
|
6042
|
+
if (ch === quote) break;
|
|
6043
|
+
if (ch === 38) {
|
|
6044
|
+
out += this.input.slice(chunkStart, this.pos);
|
|
6045
|
+
out += this.jsx_readEntity();
|
|
6046
|
+
chunkStart = this.pos;
|
|
6047
|
+
} else if (isNewLine2(ch)) {
|
|
6048
|
+
out += this.input.slice(chunkStart, this.pos);
|
|
6049
|
+
out += this.jsx_readNewLine(false);
|
|
6050
|
+
chunkStart = this.pos;
|
|
6051
|
+
} else {
|
|
6052
|
+
++this.pos;
|
|
6053
|
+
}
|
|
6054
|
+
}
|
|
6055
|
+
out += this.input.slice(chunkStart, this.pos++);
|
|
6056
|
+
return this.finishToken(tt.string, out);
|
|
6057
|
+
}
|
|
6058
|
+
jsx_readEntity() {
|
|
6059
|
+
let str = "", count = 0, entity;
|
|
6060
|
+
let ch = this.input[this.pos];
|
|
6061
|
+
if (ch !== "&")
|
|
6062
|
+
this.raise(this.pos, "Entity must start with an ampersand");
|
|
6063
|
+
let startPos = ++this.pos;
|
|
6064
|
+
while (this.pos < this.input.length && count++ < 10) {
|
|
6065
|
+
ch = this.input[this.pos++];
|
|
6066
|
+
if (ch === ";") {
|
|
6067
|
+
if (str[0] === "#") {
|
|
6068
|
+
if (str[1] === "x") {
|
|
6069
|
+
str = str.substr(2);
|
|
6070
|
+
if (hexNumber.test(str))
|
|
6071
|
+
entity = String.fromCharCode(parseInt(str, 16));
|
|
6072
|
+
} else {
|
|
6073
|
+
str = str.substr(1);
|
|
6074
|
+
if (decimalNumber.test(str))
|
|
6075
|
+
entity = String.fromCharCode(parseInt(str, 10));
|
|
6076
|
+
}
|
|
6077
|
+
} else {
|
|
6078
|
+
entity = XHTMLEntities[str];
|
|
6079
|
+
}
|
|
6080
|
+
break;
|
|
6081
|
+
}
|
|
6082
|
+
str += ch;
|
|
6083
|
+
}
|
|
6084
|
+
if (!entity) {
|
|
6085
|
+
this.pos = startPos;
|
|
6086
|
+
return "&";
|
|
6087
|
+
}
|
|
6088
|
+
return entity;
|
|
6089
|
+
}
|
|
6090
|
+
// Read a JSX identifier (valid tag or attribute name).
|
|
6091
|
+
//
|
|
6092
|
+
// Optimized version since JSX identifiers can't contain
|
|
6093
|
+
// escape characters and so can be read as single slice.
|
|
6094
|
+
// Also assumes that first character was already checked
|
|
6095
|
+
// by isIdentifierStart in readToken.
|
|
6096
|
+
jsx_readWord() {
|
|
6097
|
+
let ch, start = this.pos;
|
|
6098
|
+
do {
|
|
6099
|
+
ch = this.input.charCodeAt(++this.pos);
|
|
6100
|
+
} while (isIdentifierChar2(ch) || ch === 45);
|
|
6101
|
+
return this.finishToken(tok.jsxName, this.input.slice(start, this.pos));
|
|
6102
|
+
}
|
|
6103
|
+
// Parse next token as JSX identifier
|
|
6104
|
+
jsx_parseIdentifier() {
|
|
6105
|
+
let node = this.startNode();
|
|
6106
|
+
if (this.type === tok.jsxName)
|
|
6107
|
+
node.name = this.value;
|
|
6108
|
+
else if (this.type.keyword)
|
|
6109
|
+
node.name = this.type.keyword;
|
|
6110
|
+
else
|
|
6111
|
+
this.unexpected();
|
|
6112
|
+
this.next();
|
|
6113
|
+
return this.finishNode(node, "JSXIdentifier");
|
|
6114
|
+
}
|
|
6115
|
+
// Parse namespaced identifier.
|
|
6116
|
+
jsx_parseNamespacedName() {
|
|
6117
|
+
let startPos = this.start, startLoc = this.startLoc;
|
|
6118
|
+
let name = this.jsx_parseIdentifier();
|
|
6119
|
+
if (!options.allowNamespaces || !this.eat(tt.colon)) return name;
|
|
6120
|
+
var node = this.startNodeAt(startPos, startLoc);
|
|
6121
|
+
node.namespace = name;
|
|
6122
|
+
node.name = this.jsx_parseIdentifier();
|
|
6123
|
+
return this.finishNode(node, "JSXNamespacedName");
|
|
6124
|
+
}
|
|
6125
|
+
// Parses element name in any form - namespaced, member
|
|
6126
|
+
// or single identifier.
|
|
6127
|
+
jsx_parseElementName() {
|
|
6128
|
+
if (this.type === tok.jsxTagEnd) return "";
|
|
6129
|
+
let startPos = this.start, startLoc = this.startLoc;
|
|
6130
|
+
let node = this.jsx_parseNamespacedName();
|
|
6131
|
+
if (this.type === tt.dot && node.type === "JSXNamespacedName" && !options.allowNamespacedObjects) {
|
|
6132
|
+
this.unexpected();
|
|
6133
|
+
}
|
|
6134
|
+
while (this.eat(tt.dot)) {
|
|
6135
|
+
let newNode = this.startNodeAt(startPos, startLoc);
|
|
6136
|
+
newNode.object = node;
|
|
6137
|
+
newNode.property = this.jsx_parseIdentifier();
|
|
6138
|
+
node = this.finishNode(newNode, "JSXMemberExpression");
|
|
6139
|
+
}
|
|
6140
|
+
return node;
|
|
6141
|
+
}
|
|
6142
|
+
// Parses any type of JSX attribute value.
|
|
6143
|
+
jsx_parseAttributeValue() {
|
|
6144
|
+
switch (this.type) {
|
|
6145
|
+
case tt.braceL:
|
|
6146
|
+
let node = this.jsx_parseExpressionContainer();
|
|
6147
|
+
if (node.expression.type === "JSXEmptyExpression")
|
|
6148
|
+
this.raise(node.start, "JSX attributes must only be assigned a non-empty expression");
|
|
6149
|
+
return node;
|
|
6150
|
+
case tok.jsxTagStart:
|
|
6151
|
+
case tt.string:
|
|
6152
|
+
return this.parseExprAtom();
|
|
6153
|
+
default:
|
|
6154
|
+
this.raise(this.start, "JSX value should be either an expression or a quoted JSX text");
|
|
6155
|
+
}
|
|
6156
|
+
}
|
|
6157
|
+
// JSXEmptyExpression is unique type since it doesn't actually parse anything,
|
|
6158
|
+
// and so it should start at the end of last read token (left brace) and finish
|
|
6159
|
+
// at the beginning of the next one (right brace).
|
|
6160
|
+
jsx_parseEmptyExpression() {
|
|
6161
|
+
let node = this.startNodeAt(this.lastTokEnd, this.lastTokEndLoc);
|
|
6162
|
+
return this.finishNodeAt(node, "JSXEmptyExpression", this.start, this.startLoc);
|
|
6163
|
+
}
|
|
6164
|
+
// Parses JSX expression enclosed into curly brackets.
|
|
6165
|
+
jsx_parseExpressionContainer() {
|
|
6166
|
+
let node = this.startNode();
|
|
6167
|
+
this.next();
|
|
6168
|
+
node.expression = this.type === tt.braceR ? this.jsx_parseEmptyExpression() : this.parseExpression();
|
|
6169
|
+
this.expect(tt.braceR);
|
|
6170
|
+
return this.finishNode(node, "JSXExpressionContainer");
|
|
6171
|
+
}
|
|
6172
|
+
// Parses following JSX attribute name-value pair.
|
|
6173
|
+
jsx_parseAttribute() {
|
|
6174
|
+
let node = this.startNode();
|
|
6175
|
+
if (this.eat(tt.braceL)) {
|
|
6176
|
+
this.expect(tt.ellipsis);
|
|
6177
|
+
node.argument = this.parseMaybeAssign();
|
|
6178
|
+
this.expect(tt.braceR);
|
|
6179
|
+
return this.finishNode(node, "JSXSpreadAttribute");
|
|
6180
|
+
}
|
|
6181
|
+
node.name = this.jsx_parseNamespacedName();
|
|
6182
|
+
node.value = this.eat(tt.eq) ? this.jsx_parseAttributeValue() : null;
|
|
6183
|
+
return this.finishNode(node, "JSXAttribute");
|
|
6184
|
+
}
|
|
6185
|
+
// Parses JSX opening tag starting after '<'.
|
|
6186
|
+
jsx_parseOpeningElementAt(startPos, startLoc) {
|
|
6187
|
+
let node = this.startNodeAt(startPos, startLoc);
|
|
6188
|
+
node.attributes = [];
|
|
6189
|
+
let nodeName = this.jsx_parseElementName();
|
|
6190
|
+
if (nodeName) node.name = nodeName;
|
|
6191
|
+
while (this.type !== tt.slash && this.type !== tok.jsxTagEnd)
|
|
6192
|
+
node.attributes.push(this.jsx_parseAttribute());
|
|
6193
|
+
node.selfClosing = this.eat(tt.slash);
|
|
6194
|
+
this.expect(tok.jsxTagEnd);
|
|
6195
|
+
return this.finishNode(node, nodeName ? "JSXOpeningElement" : "JSXOpeningFragment");
|
|
6196
|
+
}
|
|
6197
|
+
// Parses JSX closing tag starting after '</'.
|
|
6198
|
+
jsx_parseClosingElementAt(startPos, startLoc) {
|
|
6199
|
+
let node = this.startNodeAt(startPos, startLoc);
|
|
6200
|
+
let nodeName = this.jsx_parseElementName();
|
|
6201
|
+
if (nodeName) node.name = nodeName;
|
|
6202
|
+
this.expect(tok.jsxTagEnd);
|
|
6203
|
+
return this.finishNode(node, nodeName ? "JSXClosingElement" : "JSXClosingFragment");
|
|
6204
|
+
}
|
|
6205
|
+
// Parses entire JSX element, including it's opening tag
|
|
6206
|
+
// (starting after '<'), attributes, contents and closing tag.
|
|
6207
|
+
jsx_parseElementAt(startPos, startLoc) {
|
|
6208
|
+
let node = this.startNodeAt(startPos, startLoc);
|
|
6209
|
+
let children = [];
|
|
6210
|
+
let openingElement = this.jsx_parseOpeningElementAt(startPos, startLoc);
|
|
6211
|
+
let closingElement = null;
|
|
6212
|
+
if (!openingElement.selfClosing) {
|
|
6213
|
+
contents: for (; ; ) {
|
|
6214
|
+
switch (this.type) {
|
|
6215
|
+
case tok.jsxTagStart:
|
|
6216
|
+
startPos = this.start;
|
|
6217
|
+
startLoc = this.startLoc;
|
|
6218
|
+
this.next();
|
|
6219
|
+
if (this.eat(tt.slash)) {
|
|
6220
|
+
closingElement = this.jsx_parseClosingElementAt(startPos, startLoc);
|
|
6221
|
+
break contents;
|
|
6222
|
+
}
|
|
6223
|
+
children.push(this.jsx_parseElementAt(startPos, startLoc));
|
|
6224
|
+
break;
|
|
6225
|
+
case tok.jsxText:
|
|
6226
|
+
children.push(this.parseExprAtom());
|
|
6227
|
+
break;
|
|
6228
|
+
case tt.braceL:
|
|
6229
|
+
children.push(this.jsx_parseExpressionContainer());
|
|
6230
|
+
break;
|
|
6231
|
+
default:
|
|
6232
|
+
this.unexpected();
|
|
6233
|
+
}
|
|
6234
|
+
}
|
|
6235
|
+
if (getQualifiedJSXName(closingElement.name) !== getQualifiedJSXName(openingElement.name)) {
|
|
6236
|
+
this.raise(
|
|
6237
|
+
closingElement.start,
|
|
6238
|
+
"Expected corresponding JSX closing tag for <" + getQualifiedJSXName(openingElement.name) + ">"
|
|
6239
|
+
);
|
|
6240
|
+
}
|
|
6241
|
+
}
|
|
6242
|
+
let fragmentOrElement = openingElement.name ? "Element" : "Fragment";
|
|
6243
|
+
node["opening" + fragmentOrElement] = openingElement;
|
|
6244
|
+
node["closing" + fragmentOrElement] = closingElement;
|
|
6245
|
+
node.children = children;
|
|
6246
|
+
if (this.type === tt.relational && this.value === "<") {
|
|
6247
|
+
this.raise(this.start, "Adjacent JSX elements must be wrapped in an enclosing tag");
|
|
6248
|
+
}
|
|
6249
|
+
return this.finishNode(node, "JSX" + fragmentOrElement);
|
|
6250
|
+
}
|
|
6251
|
+
// Parse JSX text
|
|
6252
|
+
jsx_parseText() {
|
|
6253
|
+
let node = this.parseLiteral(this.value);
|
|
6254
|
+
node.type = "JSXText";
|
|
6255
|
+
return node;
|
|
6256
|
+
}
|
|
6257
|
+
// Parses entire JSX element from current position.
|
|
6258
|
+
jsx_parseElement() {
|
|
6259
|
+
let startPos = this.start, startLoc = this.startLoc;
|
|
6260
|
+
this.next();
|
|
6261
|
+
return this.jsx_parseElementAt(startPos, startLoc);
|
|
6262
|
+
}
|
|
6263
|
+
parseExprAtom(refShortHandDefaultPos) {
|
|
6264
|
+
if (this.type === tok.jsxText)
|
|
6265
|
+
return this.jsx_parseText();
|
|
6266
|
+
else if (this.type === tok.jsxTagStart)
|
|
6267
|
+
return this.jsx_parseElement();
|
|
6268
|
+
else
|
|
6269
|
+
return super.parseExprAtom(refShortHandDefaultPos);
|
|
6270
|
+
}
|
|
6271
|
+
readToken(code) {
|
|
6272
|
+
let context = this.curContext();
|
|
6273
|
+
if (context === tc_expr) return this.jsx_readToken();
|
|
6274
|
+
if (context === tc_oTag || context === tc_cTag) {
|
|
6275
|
+
if (isIdentifierStart2(code)) return this.jsx_readWord();
|
|
6276
|
+
if (code == 62) {
|
|
6277
|
+
++this.pos;
|
|
6278
|
+
return this.finishToken(tok.jsxTagEnd);
|
|
6279
|
+
}
|
|
6280
|
+
if ((code === 34 || code === 39) && context == tc_oTag)
|
|
6281
|
+
return this.jsx_readString(code);
|
|
6282
|
+
}
|
|
6283
|
+
if (code === 60 && this.exprAllowed && this.input.charCodeAt(this.pos + 1) !== 33) {
|
|
6284
|
+
++this.pos;
|
|
6285
|
+
return this.finishToken(tok.jsxTagStart);
|
|
6286
|
+
}
|
|
6287
|
+
return super.readToken(code);
|
|
6288
|
+
}
|
|
6289
|
+
updateContext(prevType) {
|
|
6290
|
+
if (this.type == tt.braceL) {
|
|
6291
|
+
var curContext = this.curContext();
|
|
6292
|
+
if (curContext == tc_oTag) this.context.push(tokContexts.b_expr);
|
|
6293
|
+
else if (curContext == tc_expr) this.context.push(tokContexts.b_tmpl);
|
|
6294
|
+
else super.updateContext(prevType);
|
|
6295
|
+
this.exprAllowed = true;
|
|
6296
|
+
} else if (this.type === tt.slash && prevType === tok.jsxTagStart) {
|
|
6297
|
+
this.context.length -= 2;
|
|
6298
|
+
this.context.push(tc_cTag);
|
|
6299
|
+
this.exprAllowed = false;
|
|
6300
|
+
} else {
|
|
6301
|
+
return super.updateContext(prevType);
|
|
6302
|
+
}
|
|
6303
|
+
}
|
|
6304
|
+
};
|
|
6305
|
+
}
|
|
6306
|
+
var JSXParser = Parser.extend(acornJsx());
|
|
6307
|
+
function jsxParse(input, options) {
|
|
6308
|
+
return JSXParser.parse(input, options);
|
|
5645
6309
|
}
|
|
5646
6310
|
|
|
5647
6311
|
// src/runtime/environment.js
|
|
@@ -6315,6 +6979,21 @@ var Interpreter = class _Interpreter {
|
|
|
6315
6979
|
if (node.type === "ClassExpression") {
|
|
6316
6980
|
return this.evaluateClassExpression(node, env);
|
|
6317
6981
|
}
|
|
6982
|
+
if (node.type === "JSXElement") {
|
|
6983
|
+
return await this.evaluateJSXElementAsync(node, env);
|
|
6984
|
+
}
|
|
6985
|
+
if (node.type === "JSXFragment") {
|
|
6986
|
+
return await this.evaluateJSXFragmentAsync(node, env);
|
|
6987
|
+
}
|
|
6988
|
+
if (node.type === "JSXExpressionContainer") {
|
|
6989
|
+
if (node.expression.type === "JSXEmptyExpression") {
|
|
6990
|
+
return void 0;
|
|
6991
|
+
}
|
|
6992
|
+
return await this.evaluateAsync(node.expression, env);
|
|
6993
|
+
}
|
|
6994
|
+
if (node.type === "JSXText") {
|
|
6995
|
+
return this.normalizeJSXText(node.value);
|
|
6996
|
+
}
|
|
6318
6997
|
if ([
|
|
6319
6998
|
"Literal",
|
|
6320
6999
|
"Identifier",
|
|
@@ -6437,6 +7116,18 @@ var Interpreter = class _Interpreter {
|
|
|
6437
7116
|
return this.evaluateAssignmentPattern(node, env);
|
|
6438
7117
|
case "Property":
|
|
6439
7118
|
return this.evaluateProperty(node, env);
|
|
7119
|
+
// JSX Support
|
|
7120
|
+
case "JSXElement":
|
|
7121
|
+
return this.evaluateJSXElement(node, env);
|
|
7122
|
+
case "JSXFragment":
|
|
7123
|
+
return this.evaluateJSXFragment(node, env);
|
|
7124
|
+
case "JSXExpressionContainer":
|
|
7125
|
+
if (node.expression.type === "JSXEmptyExpression") {
|
|
7126
|
+
return void 0;
|
|
7127
|
+
}
|
|
7128
|
+
return this.evaluate(node.expression, env);
|
|
7129
|
+
case "JSXText":
|
|
7130
|
+
return this.normalizeJSXText(node.value);
|
|
6440
7131
|
default:
|
|
6441
7132
|
throw new Error(`Unknown node type: ${node.type}`);
|
|
6442
7133
|
}
|
|
@@ -7075,7 +7766,7 @@ var Interpreter = class _Interpreter {
|
|
|
7075
7766
|
throw new Error(`Cannot find module '${modulePath}'`);
|
|
7076
7767
|
}
|
|
7077
7768
|
const moduleCode = typeof resolution === "string" ? resolution : resolution.code;
|
|
7078
|
-
const moduleAst =
|
|
7769
|
+
const moduleAst = jsxParse(moduleCode, {
|
|
7079
7770
|
ecmaVersion: 2020,
|
|
7080
7771
|
sourceType: "module",
|
|
7081
7772
|
locations: false
|
|
@@ -7504,6 +8195,210 @@ var Interpreter = class _Interpreter {
|
|
|
7504
8195
|
evaluateProperty(node, env) {
|
|
7505
8196
|
return void 0;
|
|
7506
8197
|
}
|
|
8198
|
+
// ===== JSX Support =====
|
|
8199
|
+
evaluateJSXElement(node, env) {
|
|
8200
|
+
const createElement = this.getCreateElement(env);
|
|
8201
|
+
const { type, props } = this.evaluateJSXOpeningElement(node.openingElement, env);
|
|
8202
|
+
const children = this.evaluateJSXChildren(node.children, env);
|
|
8203
|
+
if (children.length === 0) {
|
|
8204
|
+
return createElement(type, props);
|
|
8205
|
+
} else if (children.length === 1) {
|
|
8206
|
+
return createElement(type, props, children[0]);
|
|
8207
|
+
}
|
|
8208
|
+
return createElement(type, props, ...children);
|
|
8209
|
+
}
|
|
8210
|
+
evaluateJSXFragment(node, env) {
|
|
8211
|
+
const createElement = this.getCreateElement(env);
|
|
8212
|
+
const Fragment = this.getFragment(env);
|
|
8213
|
+
const children = this.evaluateJSXChildren(node.children, env);
|
|
8214
|
+
if (children.length === 0) {
|
|
8215
|
+
return createElement(Fragment, null);
|
|
8216
|
+
} else if (children.length === 1) {
|
|
8217
|
+
return createElement(Fragment, null, children[0]);
|
|
8218
|
+
}
|
|
8219
|
+
return createElement(Fragment, null, ...children);
|
|
8220
|
+
}
|
|
8221
|
+
evaluateJSXOpeningElement(node, env) {
|
|
8222
|
+
const type = this.evaluateJSXElementName(node.name, env);
|
|
8223
|
+
const props = {};
|
|
8224
|
+
for (const attr of node.attributes) {
|
|
8225
|
+
if (attr.type === "JSXAttribute") {
|
|
8226
|
+
const name = attr.name.type === "JSXIdentifier" ? attr.name.name : `${attr.name.namespace.name}:${attr.name.name.name}`;
|
|
8227
|
+
const value = attr.value ? this.evaluateJSXAttributeValue(attr.value, env) : true;
|
|
8228
|
+
props[name] = value;
|
|
8229
|
+
} else if (attr.type === "JSXSpreadAttribute") {
|
|
8230
|
+
Object.assign(props, this.evaluate(attr.argument, env));
|
|
8231
|
+
}
|
|
8232
|
+
}
|
|
8233
|
+
return { type, props: Object.keys(props).length > 0 ? props : null };
|
|
8234
|
+
}
|
|
8235
|
+
evaluateJSXElementName(node, env) {
|
|
8236
|
+
if (node.type === "JSXIdentifier") {
|
|
8237
|
+
const name = node.name;
|
|
8238
|
+
if (name[0] === name[0].toLowerCase()) {
|
|
8239
|
+
return name;
|
|
8240
|
+
}
|
|
8241
|
+
return env.get(name);
|
|
8242
|
+
} else if (node.type === "JSXMemberExpression") {
|
|
8243
|
+
const object = this.evaluateJSXElementName(node.object, env);
|
|
8244
|
+
return object[node.property.name];
|
|
8245
|
+
} else if (node.type === "JSXNamespacedName") {
|
|
8246
|
+
return `${node.namespace.name}:${node.name.name}`;
|
|
8247
|
+
}
|
|
8248
|
+
throw new Error(`Unknown JSX element name type: ${node.type}`);
|
|
8249
|
+
}
|
|
8250
|
+
evaluateJSXAttributeValue(node, env) {
|
|
8251
|
+
if (node.type === "Literal") return node.value;
|
|
8252
|
+
if (node.type === "JSXExpressionContainer") {
|
|
8253
|
+
return this.evaluate(node.expression, env);
|
|
8254
|
+
}
|
|
8255
|
+
if (node.type === "JSXElement") return this.evaluateJSXElement(node, env);
|
|
8256
|
+
if (node.type === "JSXFragment") return this.evaluateJSXFragment(node, env);
|
|
8257
|
+
throw new Error(`Unknown JSX attribute value type: ${node.type}`);
|
|
8258
|
+
}
|
|
8259
|
+
evaluateJSXChildren(children, env) {
|
|
8260
|
+
const result = [];
|
|
8261
|
+
for (const child of children) {
|
|
8262
|
+
if (child.type === "JSXText") {
|
|
8263
|
+
const text = this.normalizeJSXText(child.value);
|
|
8264
|
+
if (text) result.push(text);
|
|
8265
|
+
} else if (child.type === "JSXExpressionContainer") {
|
|
8266
|
+
if (child.expression.type !== "JSXEmptyExpression") {
|
|
8267
|
+
const value = this.evaluate(child.expression, env);
|
|
8268
|
+
if (Array.isArray(value)) {
|
|
8269
|
+
result.push(...value);
|
|
8270
|
+
} else if (value !== null && value !== void 0 && value !== false) {
|
|
8271
|
+
result.push(value);
|
|
8272
|
+
}
|
|
8273
|
+
}
|
|
8274
|
+
} else if (child.type === "JSXElement") {
|
|
8275
|
+
result.push(this.evaluateJSXElement(child, env));
|
|
8276
|
+
} else if (child.type === "JSXFragment") {
|
|
8277
|
+
result.push(this.evaluateJSXFragment(child, env));
|
|
8278
|
+
}
|
|
8279
|
+
}
|
|
8280
|
+
return result;
|
|
8281
|
+
}
|
|
8282
|
+
normalizeJSXText(text) {
|
|
8283
|
+
const lines = text.split("\n");
|
|
8284
|
+
const normalized = lines.map((line, i) => {
|
|
8285
|
+
let result = line;
|
|
8286
|
+
if (i === 0) result = result.trimStart();
|
|
8287
|
+
if (i === lines.length - 1) result = result.trimEnd();
|
|
8288
|
+
return result;
|
|
8289
|
+
}).filter((line) => line.length > 0).join(" ");
|
|
8290
|
+
return normalized || null;
|
|
8291
|
+
}
|
|
8292
|
+
getCreateElement(env) {
|
|
8293
|
+
try {
|
|
8294
|
+
const React = env.get("React");
|
|
8295
|
+
if (React && React.createElement) {
|
|
8296
|
+
return React.createElement.bind(React);
|
|
8297
|
+
}
|
|
8298
|
+
} catch (e) {
|
|
8299
|
+
}
|
|
8300
|
+
try {
|
|
8301
|
+
return env.get("createElement");
|
|
8302
|
+
} catch (e) {
|
|
8303
|
+
}
|
|
8304
|
+
return (type, props, ...children) => ({
|
|
8305
|
+
$$typeof: Symbol.for("react.element"),
|
|
8306
|
+
type,
|
|
8307
|
+
props: {
|
|
8308
|
+
...props,
|
|
8309
|
+
children: children.length === 0 ? void 0 : children.length === 1 ? children[0] : children
|
|
8310
|
+
},
|
|
8311
|
+
key: (props == null ? void 0 : props.key) ?? null,
|
|
8312
|
+
ref: (props == null ? void 0 : props.ref) ?? null
|
|
8313
|
+
});
|
|
8314
|
+
}
|
|
8315
|
+
getFragment(env) {
|
|
8316
|
+
try {
|
|
8317
|
+
const React = env.get("React");
|
|
8318
|
+
if (React && React.Fragment) {
|
|
8319
|
+
return React.Fragment;
|
|
8320
|
+
}
|
|
8321
|
+
} catch (e) {
|
|
8322
|
+
}
|
|
8323
|
+
try {
|
|
8324
|
+
return env.get("Fragment");
|
|
8325
|
+
} catch (e) {
|
|
8326
|
+
}
|
|
8327
|
+
return Symbol.for("react.fragment");
|
|
8328
|
+
}
|
|
8329
|
+
// ===== Async JSX Support =====
|
|
8330
|
+
async evaluateJSXElementAsync(node, env) {
|
|
8331
|
+
const checkpointPromise = this._getCheckpointPromise(node, env);
|
|
8332
|
+
if (checkpointPromise) await checkpointPromise;
|
|
8333
|
+
const createElement = this.getCreateElement(env);
|
|
8334
|
+
const { type, props } = await this.evaluateJSXOpeningElementAsync(node.openingElement, env);
|
|
8335
|
+
const children = await this.evaluateJSXChildrenAsync(node.children, env);
|
|
8336
|
+
if (children.length === 0) {
|
|
8337
|
+
return createElement(type, props);
|
|
8338
|
+
} else if (children.length === 1) {
|
|
8339
|
+
return createElement(type, props, children[0]);
|
|
8340
|
+
}
|
|
8341
|
+
return createElement(type, props, ...children);
|
|
8342
|
+
}
|
|
8343
|
+
async evaluateJSXFragmentAsync(node, env) {
|
|
8344
|
+
const checkpointPromise = this._getCheckpointPromise(node, env);
|
|
8345
|
+
if (checkpointPromise) await checkpointPromise;
|
|
8346
|
+
const createElement = this.getCreateElement(env);
|
|
8347
|
+
const Fragment = this.getFragment(env);
|
|
8348
|
+
const children = await this.evaluateJSXChildrenAsync(node.children, env);
|
|
8349
|
+
if (children.length === 0) {
|
|
8350
|
+
return createElement(Fragment, null);
|
|
8351
|
+
} else if (children.length === 1) {
|
|
8352
|
+
return createElement(Fragment, null, children[0]);
|
|
8353
|
+
}
|
|
8354
|
+
return createElement(Fragment, null, ...children);
|
|
8355
|
+
}
|
|
8356
|
+
async evaluateJSXOpeningElementAsync(node, env) {
|
|
8357
|
+
const type = this.evaluateJSXElementName(node.name, env);
|
|
8358
|
+
const props = {};
|
|
8359
|
+
for (const attr of node.attributes) {
|
|
8360
|
+
if (attr.type === "JSXAttribute") {
|
|
8361
|
+
const name = attr.name.type === "JSXIdentifier" ? attr.name.name : `${attr.name.namespace.name}:${attr.name.name.name}`;
|
|
8362
|
+
const value = attr.value ? await this.evaluateJSXAttributeValueAsync(attr.value, env) : true;
|
|
8363
|
+
props[name] = value;
|
|
8364
|
+
} else if (attr.type === "JSXSpreadAttribute") {
|
|
8365
|
+
Object.assign(props, await this.evaluateAsync(attr.argument, env));
|
|
8366
|
+
}
|
|
8367
|
+
}
|
|
8368
|
+
return { type, props: Object.keys(props).length > 0 ? props : null };
|
|
8369
|
+
}
|
|
8370
|
+
async evaluateJSXAttributeValueAsync(node, env) {
|
|
8371
|
+
if (node.type === "Literal") return node.value;
|
|
8372
|
+
if (node.type === "JSXExpressionContainer") {
|
|
8373
|
+
return await this.evaluateAsync(node.expression, env);
|
|
8374
|
+
}
|
|
8375
|
+
if (node.type === "JSXElement") return await this.evaluateJSXElementAsync(node, env);
|
|
8376
|
+
if (node.type === "JSXFragment") return await this.evaluateJSXFragmentAsync(node, env);
|
|
8377
|
+
throw new Error(`Unknown JSX attribute value type: ${node.type}`);
|
|
8378
|
+
}
|
|
8379
|
+
async evaluateJSXChildrenAsync(children, env) {
|
|
8380
|
+
const result = [];
|
|
8381
|
+
for (const child of children) {
|
|
8382
|
+
if (child.type === "JSXText") {
|
|
8383
|
+
const text = this.normalizeJSXText(child.value);
|
|
8384
|
+
if (text) result.push(text);
|
|
8385
|
+
} else if (child.type === "JSXExpressionContainer") {
|
|
8386
|
+
if (child.expression.type !== "JSXEmptyExpression") {
|
|
8387
|
+
const value = await this.evaluateAsync(child.expression, env);
|
|
8388
|
+
if (Array.isArray(value)) {
|
|
8389
|
+
result.push(...value);
|
|
8390
|
+
} else if (value !== null && value !== void 0 && value !== false) {
|
|
8391
|
+
result.push(value);
|
|
8392
|
+
}
|
|
8393
|
+
}
|
|
8394
|
+
} else if (child.type === "JSXElement") {
|
|
8395
|
+
result.push(await this.evaluateJSXElementAsync(child, env));
|
|
8396
|
+
} else if (child.type === "JSXFragment") {
|
|
8397
|
+
result.push(await this.evaluateJSXFragmentAsync(child, env));
|
|
8398
|
+
}
|
|
8399
|
+
}
|
|
8400
|
+
return result;
|
|
8401
|
+
}
|
|
7507
8402
|
};
|
|
7508
8403
|
|
|
7509
8404
|
// src/runtime/builtins.js
|
|
@@ -7585,6 +8480,17 @@ function createGlobalEnvironment(env) {
|
|
|
7585
8480
|
env.define("ReferenceError", ReferenceError);
|
|
7586
8481
|
env.define("SyntaxError", SyntaxError);
|
|
7587
8482
|
env.define("RangeError", RangeError);
|
|
8483
|
+
env.define("createElement", (type, props, ...children) => ({
|
|
8484
|
+
$$typeof: Symbol.for("react.element"),
|
|
8485
|
+
type,
|
|
8486
|
+
props: {
|
|
8487
|
+
...props,
|
|
8488
|
+
children: children.length === 0 ? void 0 : children.length === 1 ? children[0] : children
|
|
8489
|
+
},
|
|
8490
|
+
key: (props == null ? void 0 : props.key) ?? null,
|
|
8491
|
+
ref: (props == null ? void 0 : props.ref) ?? null
|
|
8492
|
+
}));
|
|
8493
|
+
env.define("Fragment", Symbol.for("react.fragment"));
|
|
7588
8494
|
env.define("log", (...args) => {
|
|
7589
8495
|
console.log(...args);
|
|
7590
8496
|
return void 0;
|
|
@@ -8248,14 +9154,14 @@ function containsModuleSyntax(code) {
|
|
|
8248
9154
|
}
|
|
8249
9155
|
return false;
|
|
8250
9156
|
}
|
|
8251
|
-
function
|
|
9157
|
+
function parse3(code, options = {}) {
|
|
8252
9158
|
var _a;
|
|
8253
9159
|
let sourceType = options.sourceType || "script";
|
|
8254
9160
|
if (!options.sourceType && containsModuleSyntax(code)) {
|
|
8255
9161
|
sourceType = "module";
|
|
8256
9162
|
}
|
|
8257
9163
|
try {
|
|
8258
|
-
return
|
|
9164
|
+
return jsxParse(code, {
|
|
8259
9165
|
ecmaVersion: 2022,
|
|
8260
9166
|
// Support ES2022 features (including top-level await)
|
|
8261
9167
|
sourceType,
|
|
@@ -8309,7 +9215,7 @@ async function execute(code, env = null, options = {}) {
|
|
|
8309
9215
|
controller._start();
|
|
8310
9216
|
}
|
|
8311
9217
|
try {
|
|
8312
|
-
const ast =
|
|
9218
|
+
const ast = parse3(code, options);
|
|
8313
9219
|
if (!env) {
|
|
8314
9220
|
env = createGlobalEnvironment(new Environment());
|
|
8315
9221
|
}
|