@tsrx/core 0.1.0 → 0.1.2
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/package.json +1 -1
- package/src/plugin.js +42 -2
package/package.json
CHANGED
package/src/plugin.js
CHANGED
|
@@ -202,6 +202,7 @@ export function TSRXPlugin(config) {
|
|
|
202
202
|
// Some parser constructors (e.g. via TS plugins) expose `tokContexts` without `b_stat`.
|
|
203
203
|
// If we push an undefined context, Acorn's tokenizer will later crash reading `.override`.
|
|
204
204
|
const b_stat = tc.b_stat || acorn.tokContexts.b_stat;
|
|
205
|
+
const b_expr = tc.b_expr || acorn.tokContexts.b_expr;
|
|
205
206
|
const tstt = Parser.acornTypeScript.tokTypes;
|
|
206
207
|
const tstc = Parser.acornTypeScript.tokContexts;
|
|
207
208
|
|
|
@@ -319,6 +320,21 @@ export function TSRXPlugin(config) {
|
|
|
319
320
|
}
|
|
320
321
|
}
|
|
321
322
|
|
|
323
|
+
#popJsxAttributeExpressionContextAfterTemplateElement() {
|
|
324
|
+
if (this.type !== tt.braceR) {
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
const context_index = this.context.length - 1;
|
|
329
|
+
if (
|
|
330
|
+
this.context[context_index] === b_expr &&
|
|
331
|
+
this.context[context_index - 1] === tstc.tc_oTag
|
|
332
|
+
) {
|
|
333
|
+
this.context.pop();
|
|
334
|
+
this.exprAllowed = false;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
322
338
|
#isDoubleQuotedTextChildStart() {
|
|
323
339
|
if (this.#path.findLast((n) => n.type === 'TsxCompat' || n.type === 'Tsx')) {
|
|
324
340
|
return false;
|
|
@@ -1702,7 +1718,22 @@ export function TSRXPlugin(config) {
|
|
|
1702
1718
|
chunkStart = this.pos;
|
|
1703
1719
|
|
|
1704
1720
|
while (true) {
|
|
1705
|
-
if (this.pos >= this.input.length)
|
|
1721
|
+
if (this.pos >= this.input.length) {
|
|
1722
|
+
const inside_open_template = this.#path.findLast(
|
|
1723
|
+
(n) =>
|
|
1724
|
+
n.type === 'Element' ||
|
|
1725
|
+
n.type === 'Tsrx' ||
|
|
1726
|
+
n.type === 'TsxCompat' ||
|
|
1727
|
+
n.type === 'Tsx',
|
|
1728
|
+
);
|
|
1729
|
+
if (!inside_open_template) {
|
|
1730
|
+
while (this.curContext() === tstc.tc_expr) {
|
|
1731
|
+
this.context.pop();
|
|
1732
|
+
}
|
|
1733
|
+
return this.finishToken(tt.eof);
|
|
1734
|
+
}
|
|
1735
|
+
this.raise(this.start, 'Unterminated JSX contents');
|
|
1736
|
+
}
|
|
1706
1737
|
let ch = this.input.charCodeAt(this.pos);
|
|
1707
1738
|
|
|
1708
1739
|
switch (ch) {
|
|
@@ -1895,9 +1926,18 @@ export function TSRXPlugin(config) {
|
|
|
1895
1926
|
// Use Ripple's parseElement to create a Tsx/Tsrx/TsxCompat node.
|
|
1896
1927
|
// Bare fragments (<></>) are shorthand for <tsx>...</tsx>.
|
|
1897
1928
|
this.next();
|
|
1898
|
-
|
|
1929
|
+
const parsed = /** @type {import('estree-jsx').JSXElement} */ (
|
|
1899
1930
|
/** @type {unknown} */ (this.parseElement())
|
|
1900
1931
|
);
|
|
1932
|
+
this.#popJsxAttributeExpressionContextAfterTemplateElement();
|
|
1933
|
+
return parsed;
|
|
1934
|
+
}
|
|
1935
|
+
|
|
1936
|
+
if (
|
|
1937
|
+
!this.#path.findLast((node) => node.type === 'Component') &&
|
|
1938
|
+
!this.#functionStack.findLast(is_pascal_case_function)
|
|
1939
|
+
) {
|
|
1940
|
+
return super.jsx_parseElement();
|
|
1901
1941
|
}
|
|
1902
1942
|
|
|
1903
1943
|
const code = this.#functionStack.findLast(is_pascal_case_function)
|