@tsrx/core 0.1.47 → 0.1.49
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/index.js +1 -1
- package/src/plugin.js +177 -42
- package/src/transform/await.js +14 -12
- package/src/transform/imports.js +96 -0
- package/src/transform/jsx/ast-builders.js +2 -81
- package/src/transform/jsx/helpers.js +13 -7
- package/src/transform/jsx/index.js +951 -727
- package/src/transform/jsx-hoist.js +2 -1
- package/src/transform/jsx-interleave.js +22 -36
- package/src/transform/scoping.js +4 -2
- package/src/transform/segments.js +20 -6
- package/src/utils/ast.js +37 -0
- package/src/utils/builders.js +22 -15
- package/types/helpers.d.ts +1 -2
- package/types/index.d.ts +88 -17
- package/types/jsx-platform.d.ts +18 -8
- package/types/parse.d.ts +66 -8
- package/types/runtime/ref.d.ts +1 -5
package/types/parse.d.ts
CHANGED
|
@@ -420,6 +420,8 @@ export namespace Parse {
|
|
|
420
420
|
export interface AcornTypeScriptExtensions {
|
|
421
421
|
tokTypes: AcornTypeScriptTokTypes;
|
|
422
422
|
tokContexts: AcornTypeScriptTokContexts;
|
|
423
|
+
/** Whether a token type can start/continue an identifier (incl. TS soft keywords) */
|
|
424
|
+
tokenIsIdentifier(token: TokenType): boolean;
|
|
423
425
|
}
|
|
424
426
|
|
|
425
427
|
export interface AcornTypeScriptFunctionBodyConfig {
|
|
@@ -427,6 +429,31 @@ export namespace Parse {
|
|
|
427
429
|
isClassMethod?: boolean;
|
|
428
430
|
}
|
|
429
431
|
|
|
432
|
+
/**
|
|
433
|
+
* Snapshot of tokenizer state returned by `lookahead()`, mirroring
|
|
434
|
+
* @sveltejs/acorn-typescript's saved lookahead state. Callers inspect the
|
|
435
|
+
* upcoming token (`type`/`value`/`start`/`containsEsc`) without consuming it,
|
|
436
|
+
* and pass the snapshot to the `*WithState` contextual helpers.
|
|
437
|
+
*/
|
|
438
|
+
export interface LookaheadState {
|
|
439
|
+
pos: number;
|
|
440
|
+
type: TokenType;
|
|
441
|
+
value: string | number | RegExp | bigint | null;
|
|
442
|
+
start: number;
|
|
443
|
+
end: number;
|
|
444
|
+
startLoc: AST.Position;
|
|
445
|
+
endLoc: AST.Position;
|
|
446
|
+
lastTokEnd: number;
|
|
447
|
+
lastTokStart: number;
|
|
448
|
+
lastTokStartLoc: AST.Position;
|
|
449
|
+
lastTokEndLoc: AST.Position;
|
|
450
|
+
context: TokContext[];
|
|
451
|
+
curLine: number;
|
|
452
|
+
lineStart: number;
|
|
453
|
+
curPosition: () => AST.Position;
|
|
454
|
+
containsEsc: boolean;
|
|
455
|
+
}
|
|
456
|
+
|
|
430
457
|
interface Scope {
|
|
431
458
|
flags: number;
|
|
432
459
|
var: string[];
|
|
@@ -496,6 +523,11 @@ export namespace Parse {
|
|
|
496
523
|
inFunction: boolean;
|
|
497
524
|
/** Whether @sveltejs/acorn-typescript is currently parsing a TypeScript type */
|
|
498
525
|
inType: boolean;
|
|
526
|
+
/**
|
|
527
|
+
* `value`/`type` kind of the import or export declaration currently being
|
|
528
|
+
* parsed (@sveltejs/acorn-typescript). `undefined` when not inside one.
|
|
529
|
+
*/
|
|
530
|
+
importOrExportOuterKind?: 'value' | 'type';
|
|
499
531
|
/** Stack of label names for break/continue statements */
|
|
500
532
|
labels: Array<{ kind: string | null; name?: string; statementStart?: number }>;
|
|
501
533
|
/** Current scope flags stack */
|
|
@@ -756,6 +788,23 @@ export namespace Parse {
|
|
|
756
788
|
*/
|
|
757
789
|
expectContextual(name: string): void;
|
|
758
790
|
|
|
791
|
+
/**
|
|
792
|
+
* Like `isContextual`, but tests a `lookahead()` snapshot instead of the
|
|
793
|
+
* current token (@sveltejs/acorn-typescript).
|
|
794
|
+
* @param keyword Keyword to check (e.g. "from", "defer")
|
|
795
|
+
* @param state Lookahead snapshot to test
|
|
796
|
+
*/
|
|
797
|
+
isContextualWithState(keyword: string, state: LookaheadState): boolean;
|
|
798
|
+
|
|
799
|
+
/**
|
|
800
|
+
* If `state` is the contextual keyword `name`, consume `nextCount` tokens
|
|
801
|
+
* and return true (@sveltejs/acorn-typescript).
|
|
802
|
+
* @param name Contextual keyword to eat (e.g. "type", "defer")
|
|
803
|
+
* @param nextCount Number of tokens to advance when it matches
|
|
804
|
+
* @param state Lookahead snapshot to test
|
|
805
|
+
*/
|
|
806
|
+
ts_eatContextualWithState(name: string, nextCount: number, state: LookaheadState): boolean;
|
|
807
|
+
|
|
759
808
|
/**
|
|
760
809
|
* Check if semicolon can be inserted at current position (ASI)
|
|
761
810
|
*/
|
|
@@ -831,10 +880,11 @@ export namespace Parse {
|
|
|
831
880
|
// Lookahead
|
|
832
881
|
// ============================================================
|
|
833
882
|
/**
|
|
834
|
-
* Look ahead
|
|
835
|
-
*
|
|
883
|
+
* Look ahead `number` tokens (default 1) without consuming, returning a
|
|
884
|
+
* snapshot of the tokenizer state at that position.
|
|
885
|
+
* @param number How many tokens to look ahead (default 1)
|
|
836
886
|
*/
|
|
837
|
-
lookahead():
|
|
887
|
+
lookahead(number?: number): LookaheadState;
|
|
838
888
|
|
|
839
889
|
/**
|
|
840
890
|
* Get next token start position
|
|
@@ -1461,7 +1511,17 @@ export namespace Parse {
|
|
|
1461
1511
|
// Module Parsing (Import/Export)
|
|
1462
1512
|
// ============================================================
|
|
1463
1513
|
/** Parse import declaration */
|
|
1464
|
-
parseImport(node: AST.
|
|
1514
|
+
parseImport(node: AST.TSRXImportDeclaration): AST.TSRXImportDeclaration;
|
|
1515
|
+
|
|
1516
|
+
/**
|
|
1517
|
+
* Parse a TypeScript import-equals declaration, `import x = require('y')`
|
|
1518
|
+
* or `import x = A.B` (@sveltejs/acorn-typescript). Typed as
|
|
1519
|
+
* `ImportDeclaration` because estree has no `TSImportEqualsDeclaration`.
|
|
1520
|
+
*/
|
|
1521
|
+
tsParseImportEqualsDeclaration(node: AST.Node, isExport?: boolean): AST.ImportDeclaration;
|
|
1522
|
+
|
|
1523
|
+
/** Parse an optional import-attributes clause (`with { … }` / `assert { … }`) */
|
|
1524
|
+
parseMaybeImportAttributes(node: AST.Node): void;
|
|
1465
1525
|
|
|
1466
1526
|
/** Parse import specifiers */
|
|
1467
1527
|
parseImportSpecifiers(): AST.ImportSpecifier[];
|
|
@@ -1617,8 +1677,7 @@ export namespace Parse {
|
|
|
1617
1677
|
* Parse JSX namespaced name (ns:name)
|
|
1618
1678
|
*/
|
|
1619
1679
|
jsx_parseNamespacedName():
|
|
1620
|
-
|
|
1621
|
-
| ReturnType<Parser['jsx_parseIdentifier']>;
|
|
1680
|
+
ESTreeJSX.JSXNamespacedName | ReturnType<Parser['jsx_parseIdentifier']>;
|
|
1622
1681
|
|
|
1623
1682
|
/**
|
|
1624
1683
|
* Parse JSX element name (identifier, member, namespaced, or a dynamic
|
|
@@ -1635,8 +1694,7 @@ export namespace Parse {
|
|
|
1635
1694
|
* @returns Attribute value (expression, string, or element)
|
|
1636
1695
|
*/
|
|
1637
1696
|
jsx_parseAttributeValue():
|
|
1638
|
-
|
|
1639
|
-
| ReturnType<Parser['parseExprAtom']>;
|
|
1697
|
+
ESTreeJSX.JSXExpressionContainer | ReturnType<Parser['parseExprAtom']>;
|
|
1640
1698
|
|
|
1641
1699
|
/**
|
|
1642
1700
|
* Parse JSX empty expression (for {})
|
package/types/runtime/ref.d.ts
CHANGED
|
@@ -14,11 +14,7 @@ export type RefValue<T = Element> =
|
|
|
14
14
|
| undefined;
|
|
15
15
|
|
|
16
16
|
export type MergeableRef<T> =
|
|
17
|
-
|
|
|
18
|
-
| MergeableRefObject<T>
|
|
19
|
-
| MergeableVueRef<T>
|
|
20
|
-
| null
|
|
21
|
-
| undefined;
|
|
17
|
+
MergeableRefCallback<T> | MergeableRefObject<T> | MergeableVueRef<T> | null | undefined;
|
|
22
18
|
|
|
23
19
|
export function mergeRefs<T = any>(...refs: Array<MergeableRef<T>>): (node: T | null) => () => void;
|
|
24
20
|
export function isRefProp(value: unknown): boolean;
|