@tslite/parser 1.10.0 → 1.12.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.
Files changed (47) hide show
  1. package/LICENSE +55 -0
  2. package/NOTICE +14 -0
  3. package/dist/_namespaces/ts.d.ts +18 -0
  4. package/dist/_namespaces/ts.js +21 -0
  5. package/dist/_namespaces/ts.performance.d.ts +1 -0
  6. package/dist/_namespaces/ts.performance.js +2 -0
  7. package/dist/core.d.ts +450 -0
  8. package/dist/core.js +1394 -0
  9. package/dist/corePublic.d.ts +62 -0
  10. package/dist/corePublic.js +31 -0
  11. package/dist/debug.d.ts +74 -0
  12. package/dist/debug.js +326 -0
  13. package/dist/diagnosticInformationMap.generated.d.ts +1435 -0
  14. package/dist/diagnosticInformationMap.generated.js +1441 -0
  15. package/dist/factory.d.ts +78 -0
  16. package/dist/factory.js +622 -0
  17. package/dist/factoryPublic.d.ts +314 -0
  18. package/dist/factoryPublic.js +1796 -0
  19. package/dist/index.d.ts +1 -249
  20. package/dist/index.js +4 -6
  21. package/dist/parser.d.ts +59 -0
  22. package/dist/parser.js +5075 -0
  23. package/dist/path.d.ts +312 -0
  24. package/dist/path.js +475 -0
  25. package/dist/perfLogger.d.ts +4 -0
  26. package/dist/perfLogger.js +38 -0
  27. package/dist/performance.d.ts +20 -0
  28. package/dist/performance.js +49 -0
  29. package/dist/performanceTimestamp.d.ts +2 -0
  30. package/dist/performanceTimestamp.js +2 -0
  31. package/dist/scanner.d.ts +80 -0
  32. package/dist/scanner.js +1984 -0
  33. package/dist/shims/mapShim.d.ts +23 -0
  34. package/dist/shims/mapShim.js +156 -0
  35. package/dist/types.d.ts +2626 -0
  36. package/dist/types.js +1074 -0
  37. package/dist/utilities.d.ts +473 -0
  38. package/dist/utilities.js +2632 -0
  39. package/dist/utilitiesPublic.d.ts +274 -0
  40. package/dist/utilitiesPublic.js +1049 -0
  41. package/dist/visitor.d.ts +15 -0
  42. package/dist/visitor.js +64 -0
  43. package/dist/visitorPublic.d.ts +82 -0
  44. package/dist/visitorPublic.js +352 -0
  45. package/package.json +14 -42
  46. package/dist/index.cjs +0 -6
  47. package/dist/index.d.cts +0 -249
@@ -0,0 +1,15 @@
1
+ import type { Node, NodeArray, Statement } from "./_namespaces/ts.js";
2
+ /**
3
+ * Merges generated lexical declarations into a new statement list.
4
+ */
5
+ export declare function mergeLexicalEnvironment(statements: NodeArray<Statement>, declarations: readonly Statement[] | undefined): NodeArray<Statement>;
6
+ /**
7
+ * Appends generated lexical declarations to an array of statements.
8
+ */
9
+ export declare function mergeLexicalEnvironment(statements: Statement[], declarations: readonly Statement[] | undefined): Statement[];
10
+ /**
11
+ * Lifts a NodeArray containing only Statement nodes to a block.
12
+ *
13
+ * @param nodes The NodeArray.
14
+ */
15
+ export declare function liftToBlock(nodes: readonly Node[]): Statement;
@@ -0,0 +1,64 @@
1
+ // Modificado de microsoft/TypeScript v3.9.10, src/compiler/visitor.ts: o namespace virou módulo ES, com os imports explícitos.
2
+ import { Debug, createBlock, createMap, createNodeArray, every, isCustomPrologue, isHoistedVariableStatement, isNodeArray, isPrologueDirective, isStatement, setTextRange, singleOrUndefined, some, } from "./_namespaces/ts.js";
3
+ function findSpanEnd(array, test, start) {
4
+ let i = start;
5
+ while (i < array.length && test(array[i])) {
6
+ i++;
7
+ }
8
+ return i;
9
+ }
10
+ export function mergeLexicalEnvironment(statements, declarations) {
11
+ if (!some(declarations)) {
12
+ return statements;
13
+ }
14
+ // As declarações novas entram na lista em faixas, na ordem: os prólogos padrão (os da direita antes dos da
15
+ // esquerda), as variáveis içadas, os statements de inicialização (os novos antes dos que já estavam) e o resto da
16
+ // lista. A declaração de função içada, que tinha a faixa dela entre os prólogos e as variáveis, não existe na
17
+ // Linguagem.
18
+ const leftStandardPrologueEnd = findSpanEnd(statements, isPrologueDirective, 0);
19
+ const leftHoistedVariablesEnd = findSpanEnd(statements, isHoistedVariableStatement, leftStandardPrologueEnd);
20
+ const rightStandardPrologueEnd = findSpanEnd(declarations, isPrologueDirective, 0);
21
+ const rightHoistedVariablesEnd = findSpanEnd(declarations, isHoistedVariableStatement, rightStandardPrologueEnd);
22
+ const rightCustomPrologueEnd = findSpanEnd(declarations, isCustomPrologue, rightHoistedVariablesEnd);
23
+ Debug.assert(rightCustomPrologueEnd === declarations.length, "Expected declarations to be valid standard or custom prologues");
24
+ // As faixas da direita entram na esquerda de trás para a frente, para não recalcular o índice da esquerda.
25
+ const left = isNodeArray(statements) ? statements.slice() : statements;
26
+ if (rightCustomPrologueEnd > rightHoistedVariablesEnd) {
27
+ left.splice(leftHoistedVariablesEnd, 0, ...declarations.slice(rightHoistedVariablesEnd, rightCustomPrologueEnd));
28
+ }
29
+ if (rightHoistedVariablesEnd > rightStandardPrologueEnd) {
30
+ left.splice(leftStandardPrologueEnd, 0, ...declarations.slice(rightStandardPrologueEnd, rightHoistedVariablesEnd));
31
+ }
32
+ // splice standard prologues from right into left (that are not already in left)
33
+ if (rightStandardPrologueEnd > 0) {
34
+ if (leftStandardPrologueEnd === 0) {
35
+ left.splice(0, 0, ...declarations.slice(0, rightStandardPrologueEnd));
36
+ }
37
+ else {
38
+ const leftPrologues = createMap();
39
+ for (let i = 0; i < leftStandardPrologueEnd; i++) {
40
+ const leftPrologue = statements[i];
41
+ leftPrologues.set(leftPrologue.expression.text, true);
42
+ }
43
+ for (let i = rightStandardPrologueEnd - 1; i >= 0; i--) {
44
+ const rightPrologue = declarations[i];
45
+ if (!leftPrologues.has(rightPrologue.expression.text)) {
46
+ left.unshift(rightPrologue);
47
+ }
48
+ }
49
+ }
50
+ }
51
+ if (isNodeArray(statements)) {
52
+ return setTextRange(createNodeArray(left, statements.hasTrailingComma), statements);
53
+ }
54
+ return statements;
55
+ }
56
+ /**
57
+ * Lifts a NodeArray containing only Statement nodes to a block.
58
+ *
59
+ * @param nodes The NodeArray.
60
+ */
61
+ export function liftToBlock(nodes) {
62
+ Debug.assert(every(nodes, isStatement), "Cannot lift nodes to a Block.");
63
+ return singleOrUndefined(nodes) || createBlock(nodes);
64
+ }
@@ -0,0 +1,82 @@
1
+ import * as ts from "./_namespaces/ts.js";
2
+ import type { ConciseBody, FunctionBody, Node, NodeArray, ParameterDeclaration, Statement, TransformationContext, Visitor } from "./_namespaces/ts.js";
3
+ /**
4
+ * Visits a Node using the supplied visitor, possibly returning a new Node in its place.
5
+ *
6
+ * @param node The Node to visit.
7
+ * @param visitor The callback used to visit the Node.
8
+ * @param test A callback to execute to verify the Node is valid.
9
+ * @param lift An optional callback to execute to lift a NodeArray into a valid Node.
10
+ */
11
+ export declare function visitNode<T extends Node>(node: T | undefined, visitor: Visitor | undefined, test?: (node: Node) => boolean, lift?: (node: readonly Node[]) => T): T;
12
+ /**
13
+ * Visits a Node using the supplied visitor, possibly returning a new Node in its place.
14
+ *
15
+ * @param node The Node to visit.
16
+ * @param visitor The callback used to visit the Node.
17
+ * @param test A callback to execute to verify the Node is valid.
18
+ * @param lift An optional callback to execute to lift a NodeArray into a valid Node.
19
+ */
20
+ export declare function visitNode<T extends Node>(node: T | undefined, visitor: Visitor | undefined, test?: (node: Node) => boolean, lift?: (node: readonly Node[]) => T): T | undefined;
21
+ /**
22
+ * Visits a NodeArray using the supplied visitor, possibly returning a new NodeArray in its place.
23
+ *
24
+ * @param nodes The NodeArray to visit.
25
+ * @param visitor The callback used to visit a Node.
26
+ * @param test A node test to execute for each node.
27
+ * @param start An optional value indicating the starting offset at which to start visiting.
28
+ * @param count An optional value indicating the maximum number of nodes to visit.
29
+ */
30
+ export declare function visitNodes<T extends Node>(nodes: NodeArray<T> | undefined, visitor: Visitor, test?: (node: Node) => boolean, start?: number, count?: number): NodeArray<T>;
31
+ /**
32
+ * Visits a NodeArray using the supplied visitor, possibly returning a new NodeArray in its place.
33
+ *
34
+ * @param nodes The NodeArray to visit.
35
+ * @param visitor The callback used to visit a Node.
36
+ * @param test A node test to execute for each node.
37
+ * @param start An optional value indicating the starting offset at which to start visiting.
38
+ * @param count An optional value indicating the maximum number of nodes to visit.
39
+ */
40
+ export declare function visitNodes<T extends Node>(nodes: NodeArray<T> | undefined, visitor: Visitor, test?: (node: Node) => boolean, start?: number, count?: number): NodeArray<T> | undefined;
41
+ /**
42
+ * Starts a new lexical environment and visits a statement list, ending the lexical environment
43
+ * and merging hoisted declarations upon completion.
44
+ */
45
+ export declare function visitLexicalEnvironment(statements: NodeArray<Statement>, visitor: Visitor, context: TransformationContext, start?: number, ensureUseStrict?: boolean): ts.NodeArray<ts.Statement>;
46
+ /**
47
+ * Starts a new lexical environment and visits a parameter list, suspending the lexical
48
+ * environment upon completion.
49
+ */
50
+ export declare function visitParameterList(nodes: NodeArray<ParameterDeclaration>, visitor: Visitor, context: TransformationContext, nodesVisitor?: typeof visitNodes): NodeArray<ParameterDeclaration>;
51
+ export declare function visitParameterList(nodes: NodeArray<ParameterDeclaration> | undefined, visitor: Visitor, context: TransformationContext, nodesVisitor?: typeof visitNodes): NodeArray<ParameterDeclaration> | undefined;
52
+ /**
53
+ * Resumes a suspended lexical environment and visits a function body, ending the lexical
54
+ * environment and merging hoisted declarations upon completion.
55
+ */
56
+ export declare function visitFunctionBody(node: FunctionBody, visitor: Visitor, context: TransformationContext): FunctionBody;
57
+ /**
58
+ * Resumes a suspended lexical environment and visits a function body, ending the lexical
59
+ * environment and merging hoisted declarations upon completion.
60
+ */
61
+ export declare function visitFunctionBody(node: FunctionBody | undefined, visitor: Visitor, context: TransformationContext): FunctionBody | undefined;
62
+ /**
63
+ * Resumes a suspended lexical environment and visits a concise body, ending the lexical
64
+ * environment and merging hoisted declarations upon completion.
65
+ */
66
+ export declare function visitFunctionBody(node: ConciseBody, visitor: Visitor, context: TransformationContext): ConciseBody;
67
+ /**
68
+ * Visits each child of a Node using the supplied visitor, possibly returning a new Node of the same kind in its place.
69
+ *
70
+ * @param node The Node whose children will be visited.
71
+ * @param visitor The callback used to visit each child.
72
+ * @param context A lexical environment context for the visitor.
73
+ */
74
+ export declare function visitEachChild<T extends Node>(node: T, visitor: Visitor, context: TransformationContext): T;
75
+ /**
76
+ * Visits each child of a Node using the supplied visitor, possibly returning a new Node of the same kind in its place.
77
+ *
78
+ * @param node The Node whose children will be visited.
79
+ * @param visitor The callback used to visit each child.
80
+ * @param context A lexical environment context for the visitor.
81
+ */
82
+ export declare function visitEachChild<T extends Node>(node: T | undefined, visitor: Visitor, context: TransformationContext, nodesVisitor?: typeof visitNodes, tokenVisitor?: Visitor): T | undefined;
@@ -0,0 +1,352 @@
1
+ // Modificado de microsoft/TypeScript v3.9.10, src/compiler/visitorPublic.ts: o namespace virou módulo ES, com os imports explícitos.
2
+ import * as ts from "./_namespaces/ts.js";
3
+ import { Debug, convertToFunctionBody, createNodeArray, isArray, isArrayBindingElement, isBindingElement, isBindingName, isBlock, isCaseBlock, isCaseOrDefaultClause, isCatchClause, isConciseBody, isEntityName, isExportSpecifier, isExpression, isForInitializer, isIdentifier, isImportClause, isImportSpecifier, isJsxAttributeLike, isJsxAttributes, isJsxChild, isJsxClosingElement, isJsxClosingFragment, isJsxOpeningElement, isJsxOpeningFragment, isJsxTagNameExpression, isModifier, isModuleBody, isNamedExportBindings, isNamedImportBindings, isObjectLiteralElementLike, isParameterDeclaration, isPropertyName, isStatement, isStringLiteralOrJsxExpression, isTemplateHead, isTemplateMiddleOrTemplateTail, isTemplateSpan, isToken, isTypeElement, isTypeNode, isTypeParameterDeclaration, isVariableDeclaration, isVariableDeclarationList, liftToBlock, mergeLexicalEnvironment, or, setTextRange, singleOrUndefined, some, updateArrayBindingPattern, updateArrayLiteral, updateArrayTypeNode, updateArrowFunction, updateAsExpression, updateAwait, updateBinary, updateBindingElement, updateBlock, updateCall, updateCallChain, updateCallSignature, updateCaseBlock, updateCaseClause, updateCatchClause, updateCommaList, updateComputedPropertyName, updateConditional, updateConditionalTypeNode, updateDefaultClause, updateDelete, updateDo, updateElementAccess, updateElementAccessChain, updateExportAssignment, updateExportDeclaration, updateExportSpecifier, updateExpressionStatement, updateFor, updateForIn, updateForOf, updateFunctionTypeNode, updateIdentifier, updateIf, updateImportClause, updateImportDeclaration, updateImportSpecifier, updateImportTypeNode, updateIndexSignature, updateIndexedAccessTypeNode, updateInferTypeNode, updateIntersectionTypeNode, updateJsxAttribute, updateJsxAttributes, updateJsxClosingElement, updateJsxElement, updateJsxExpression, updateJsxFragment, updateJsxOpeningElement, updateJsxSelfClosingElement, updateJsxSpreadAttribute, updateLiteralTypeNode, updateMappedTypeNode, updateMetaProperty, updateMethodSignature, updateModuleBlock, updateModuleDeclaration, updateNamedExports, updateNamedImports, updateNamespaceExport, updateNamespaceImport, updateObjectBindingPattern, updateObjectLiteral, updateOptionalTypeNode, updateParameter, updateParen, updateParenthesizedType, updatePartiallyEmittedExpression, updatePostfix, updatePrefix, updatePropertyAccess, updatePropertyAccessChain, updatePropertyAssignment, updatePropertySignature, updateQualifiedName, updateRestTypeNode, updateReturn, updateShorthandPropertyAssignment, updateSourceFileNode, updateSpread, updateSpreadAssignment, updateSwitch, updateTemplateExpression, updateTemplateSpan, updateThrow, updateTry, updateTupleTypeNode, updateTypeAliasDeclaration, updateTypeLiteralNode, updateTypeOf, updateTypeOperatorNode, updateTypeParameterDeclaration, updateTypePredicateNodeWithModifier, updateTypeQueryNode, updateTypeReferenceNode, updateTypeScriptVariableDeclaration, updateUnionTypeNode, updateVariableDeclarationList, updateVariableStatement, updateWhile, } from "./_namespaces/ts.js";
4
+ const isTypeNodeOrTypeParameterDeclaration = or(isTypeNode, isTypeParameterDeclaration);
5
+ export function visitNode(node, visitor, test, lift) {
6
+ if (node === undefined || visitor === undefined) {
7
+ return node;
8
+ }
9
+ const visited = visitor(node);
10
+ if (visited === node) {
11
+ return node;
12
+ }
13
+ let visitedNode;
14
+ if (visited === undefined) {
15
+ return undefined;
16
+ }
17
+ else if (isArray(visited)) {
18
+ visitedNode = (lift || extractSingleNode)(visited);
19
+ }
20
+ else {
21
+ visitedNode = visited;
22
+ }
23
+ Debug.assertNode(visitedNode, test);
24
+ return visitedNode;
25
+ }
26
+ /**
27
+ * Visits a NodeArray using the supplied visitor, possibly returning a new NodeArray in its place.
28
+ *
29
+ * @param nodes The NodeArray to visit.
30
+ * @param visitor The callback used to visit a Node.
31
+ * @param test A node test to execute for each node.
32
+ * @param start An optional value indicating the starting offset at which to start visiting.
33
+ * @param count An optional value indicating the maximum number of nodes to visit.
34
+ */
35
+ export function visitNodes(nodes, visitor, test, start, count) {
36
+ if (nodes === undefined || visitor === undefined) {
37
+ return nodes;
38
+ }
39
+ let updated;
40
+ // Ensure start and count have valid values
41
+ const length = nodes.length;
42
+ if (start === undefined || start < 0) {
43
+ start = 0;
44
+ }
45
+ if (count === undefined || count > length - start) {
46
+ count = length - start;
47
+ }
48
+ if (start > 0 || count < length) {
49
+ // If we are not visiting all of the original nodes, we must always create a new array.
50
+ // Since this is a fragment of a node array, we do not copy over the previous location
51
+ // and will only copy over `hasTrailingComma` if we are including the last element.
52
+ updated = createNodeArray([], /*hasTrailingComma*/ nodes.hasTrailingComma && start + count === length);
53
+ }
54
+ // Visit each original node.
55
+ for (let i = 0; i < count; i++) {
56
+ const node = nodes[i + start];
57
+ const visited = node !== undefined ? visitor(node) : undefined;
58
+ if (updated !== undefined || visited === undefined || visited !== node) {
59
+ if (updated === undefined) {
60
+ // Ensure we have a copy of `nodes`, up to the current index.
61
+ updated = createNodeArray(nodes.slice(0, i), nodes.hasTrailingComma);
62
+ setTextRange(updated, nodes);
63
+ }
64
+ if (visited) {
65
+ if (isArray(visited)) {
66
+ for (const visitedNode of visited) {
67
+ Debug.assertNode(visitedNode, test);
68
+ updated.push(visitedNode);
69
+ }
70
+ }
71
+ else {
72
+ Debug.assertNode(visited, test);
73
+ updated.push(visited);
74
+ }
75
+ }
76
+ }
77
+ }
78
+ return updated || nodes;
79
+ }
80
+ /**
81
+ * Starts a new lexical environment and visits a statement list, ending the lexical environment
82
+ * and merging hoisted declarations upon completion.
83
+ */
84
+ export function visitLexicalEnvironment(statements, visitor, context, start, ensureUseStrict) {
85
+ context.startLexicalEnvironment();
86
+ statements = visitNodes(statements, visitor, isStatement, start);
87
+ if (ensureUseStrict)
88
+ statements = ts.ensureUseStrict(statements); // eslint-disable-line @typescript-eslint/no-unnecessary-qualifier
89
+ return mergeLexicalEnvironment(statements, context.endLexicalEnvironment());
90
+ }
91
+ export function visitParameterList(nodes, visitor, context, nodesVisitor = visitNodes) {
92
+ let updated;
93
+ context.startLexicalEnvironment();
94
+ if (nodes) {
95
+ context.setLexicalEnvironmentFlags(1 /* LexicalEnvironmentFlags.InParameters */, true);
96
+ updated = nodesVisitor(nodes, visitor, isParameterDeclaration);
97
+ context.setLexicalEnvironmentFlags(1 /* LexicalEnvironmentFlags.InParameters */, false);
98
+ }
99
+ context.suspendLexicalEnvironment();
100
+ return updated;
101
+ }
102
+ export function visitFunctionBody(node, visitor, context) {
103
+ context.resumeLexicalEnvironment();
104
+ const updated = visitNode(node, visitor, isConciseBody);
105
+ const declarations = context.endLexicalEnvironment();
106
+ if (some(declarations)) {
107
+ const block = convertToFunctionBody(updated);
108
+ const statements = mergeLexicalEnvironment(block.statements, declarations);
109
+ return updateBlock(block, statements);
110
+ }
111
+ return updated;
112
+ }
113
+ export function visitEachChild(node, visitor, context, nodesVisitor = visitNodes, tokenVisitor) {
114
+ if (node === undefined) {
115
+ return undefined;
116
+ }
117
+ const kind = node.kind;
118
+ // O token não tem filho a visitar.
119
+ if (kind > 0 /* SyntaxKind.FirstToken */ && kind <= 152 /* SyntaxKind.LastToken */) {
120
+ return node;
121
+ }
122
+ switch (kind) {
123
+ // Names
124
+ case 75 /* SyntaxKind.Identifier */:
125
+ return updateIdentifier(node, nodesVisitor(node.typeArguments, visitor, isTypeNodeOrTypeParameterDeclaration));
126
+ case 153 /* SyntaxKind.QualifiedName */:
127
+ return updateQualifiedName(node, visitNode(node.left, visitor, isEntityName), visitNode(node.right, visitor, isIdentifier));
128
+ case 154 /* SyntaxKind.ComputedPropertyName */:
129
+ return updateComputedPropertyName(node, visitNode(node.expression, visitor, isExpression));
130
+ // Signature elements
131
+ case 155 /* SyntaxKind.TypeParameter */:
132
+ return updateTypeParameterDeclaration(node, visitNode(node.name, visitor, isIdentifier), visitNode(node.constraint, visitor, isTypeNode), visitNode(node.default, visitor, isTypeNode));
133
+ case 156 /* SyntaxKind.Parameter */:
134
+ return updateParameter(node, nodesVisitor(node.modifiers, visitor, isModifier), visitNode(node.dotDotDotToken, tokenVisitor, isToken), visitNode(node.name, visitor, isBindingName), visitNode(node.questionToken, tokenVisitor, isToken), visitNode(node.type, visitor, isTypeNode), visitNode(node.initializer, visitor, isExpression));
135
+ // Type elements
136
+ case 158 /* SyntaxKind.PropertySignature */:
137
+ return updatePropertySignature(node, nodesVisitor(node.modifiers, visitor, isToken), visitNode(node.name, visitor, isPropertyName), visitNode(node.questionToken, tokenVisitor, isToken), visitNode(node.type, visitor, isTypeNode), visitNode(node.initializer, visitor, isExpression));
138
+ case 160 /* SyntaxKind.MethodSignature */:
139
+ return updateMethodSignature(node, nodesVisitor(node.typeParameters, visitor, isTypeParameterDeclaration), nodesVisitor(node.parameters, visitor, isParameterDeclaration), visitNode(node.type, visitor, isTypeNode), visitNode(node.name, visitor, isPropertyName), visitNode(node.questionToken, tokenVisitor, isToken));
140
+ case 165 /* SyntaxKind.CallSignature */:
141
+ return updateCallSignature(node, nodesVisitor(node.typeParameters, visitor, isTypeParameterDeclaration), nodesVisitor(node.parameters, visitor, isParameterDeclaration), visitNode(node.type, visitor, isTypeNode));
142
+ case 167 /* SyntaxKind.IndexSignature */:
143
+ return updateIndexSignature(node, nodesVisitor(node.modifiers, visitor, isModifier), nodesVisitor(node.parameters, visitor, isParameterDeclaration), visitNode(node.type, visitor, isTypeNode));
144
+ // Types
145
+ case 168 /* SyntaxKind.TypePredicate */:
146
+ return updateTypePredicateNodeWithModifier(node, visitNode(node.assertsModifier, visitor), visitNode(node.parameterName, visitor), visitNode(node.type, visitor, isTypeNode));
147
+ case 169 /* SyntaxKind.TypeReference */:
148
+ return updateTypeReferenceNode(node, visitNode(node.typeName, visitor, isEntityName), nodesVisitor(node.typeArguments, visitor, isTypeNode));
149
+ case 170 /* SyntaxKind.FunctionType */:
150
+ return updateFunctionTypeNode(node, nodesVisitor(node.typeParameters, visitor, isTypeParameterDeclaration), nodesVisitor(node.parameters, visitor, isParameterDeclaration), visitNode(node.type, visitor, isTypeNode));
151
+ case 172 /* SyntaxKind.TypeQuery */:
152
+ return updateTypeQueryNode(node, visitNode(node.exprName, visitor, isEntityName));
153
+ case 173 /* SyntaxKind.TypeLiteral */:
154
+ return updateTypeLiteralNode(node, nodesVisitor(node.members, visitor, isTypeElement));
155
+ case 174 /* SyntaxKind.ArrayType */:
156
+ return updateArrayTypeNode(node, visitNode(node.elementType, visitor, isTypeNode));
157
+ case 175 /* SyntaxKind.TupleType */:
158
+ return updateTupleTypeNode(node, nodesVisitor(node.elementTypes, visitor, isTypeNode));
159
+ case 176 /* SyntaxKind.OptionalType */:
160
+ return updateOptionalTypeNode(node, visitNode(node.type, visitor, isTypeNode));
161
+ case 177 /* SyntaxKind.RestType */:
162
+ return updateRestTypeNode(node, visitNode(node.type, visitor, isTypeNode));
163
+ case 178 /* SyntaxKind.UnionType */:
164
+ return updateUnionTypeNode(node, nodesVisitor(node.types, visitor, isTypeNode));
165
+ case 179 /* SyntaxKind.IntersectionType */:
166
+ return updateIntersectionTypeNode(node, nodesVisitor(node.types, visitor, isTypeNode));
167
+ case 180 /* SyntaxKind.ConditionalType */:
168
+ return updateConditionalTypeNode(node, visitNode(node.checkType, visitor, isTypeNode), visitNode(node.extendsType, visitor, isTypeNode), visitNode(node.trueType, visitor, isTypeNode), visitNode(node.falseType, visitor, isTypeNode));
169
+ case 181 /* SyntaxKind.InferType */:
170
+ return updateInferTypeNode(node, visitNode(node.typeParameter, visitor, isTypeParameterDeclaration));
171
+ case 188 /* SyntaxKind.ImportType */:
172
+ return updateImportTypeNode(node, visitNode(node.argument, visitor, isTypeNode), visitNode(node.qualifier, visitor, isEntityName), visitNodes(node.typeArguments, visitor, isTypeNode), node.isTypeOf);
173
+ case 182 /* SyntaxKind.ParenthesizedType */:
174
+ return updateParenthesizedType(node, visitNode(node.type, visitor, isTypeNode));
175
+ case 184 /* SyntaxKind.TypeOperator */:
176
+ return updateTypeOperatorNode(node, visitNode(node.type, visitor, isTypeNode));
177
+ case 185 /* SyntaxKind.IndexedAccessType */:
178
+ return updateIndexedAccessTypeNode(node, visitNode(node.objectType, visitor, isTypeNode), visitNode(node.indexType, visitor, isTypeNode));
179
+ case 186 /* SyntaxKind.MappedType */:
180
+ return updateMappedTypeNode(node, visitNode(node.readonlyToken, tokenVisitor, isToken), visitNode(node.typeParameter, visitor, isTypeParameterDeclaration), visitNode(node.questionToken, tokenVisitor, isToken), visitNode(node.type, visitor, isTypeNode));
181
+ case 187 /* SyntaxKind.LiteralType */:
182
+ return updateLiteralTypeNode(node, visitNode(node.literal, visitor, isExpression));
183
+ // Binding patterns
184
+ case 189 /* SyntaxKind.ObjectBindingPattern */:
185
+ return updateObjectBindingPattern(node, nodesVisitor(node.elements, visitor, isBindingElement));
186
+ case 190 /* SyntaxKind.ArrayBindingPattern */:
187
+ return updateArrayBindingPattern(node, nodesVisitor(node.elements, visitor, isArrayBindingElement));
188
+ case 191 /* SyntaxKind.BindingElement */:
189
+ return updateBindingElement(node, visitNode(node.dotDotDotToken, tokenVisitor, isToken), visitNode(node.propertyName, visitor, isPropertyName), visitNode(node.name, visitor, isBindingName), visitNode(node.initializer, visitor, isExpression));
190
+ // Expression
191
+ case 192 /* SyntaxKind.ArrayLiteralExpression */:
192
+ return updateArrayLiteral(node, nodesVisitor(node.elements, visitor, isExpression));
193
+ case 193 /* SyntaxKind.ObjectLiteralExpression */:
194
+ return updateObjectLiteral(node, nodesVisitor(node.properties, visitor, isObjectLiteralElementLike));
195
+ case 194 /* SyntaxKind.PropertyAccessExpression */:
196
+ if (node.flags & 32 /* NodeFlags.OptionalChain */) {
197
+ return updatePropertyAccessChain(node, visitNode(node.expression, visitor, isExpression), visitNode(node.questionDotToken, tokenVisitor, isToken), visitNode(node.name, visitor, isIdentifier));
198
+ }
199
+ return updatePropertyAccess(node, visitNode(node.expression, visitor, isExpression), visitNode(node.name, visitor, isIdentifier));
200
+ case 195 /* SyntaxKind.ElementAccessExpression */:
201
+ if (node.flags & 32 /* NodeFlags.OptionalChain */) {
202
+ return updateElementAccessChain(node, visitNode(node.expression, visitor, isExpression), visitNode(node.questionDotToken, tokenVisitor, isToken), visitNode(node.argumentExpression, visitor, isExpression));
203
+ }
204
+ return updateElementAccess(node, visitNode(node.expression, visitor, isExpression), visitNode(node.argumentExpression, visitor, isExpression));
205
+ case 196 /* SyntaxKind.CallExpression */:
206
+ if (node.flags & 32 /* NodeFlags.OptionalChain */) {
207
+ return updateCallChain(node, visitNode(node.expression, visitor, isExpression), visitNode(node.questionDotToken, tokenVisitor, isToken), nodesVisitor(node.typeArguments, visitor, isTypeNode), nodesVisitor(node.arguments, visitor, isExpression));
208
+ }
209
+ return updateCall(node, visitNode(node.expression, visitor, isExpression), nodesVisitor(node.typeArguments, visitor, isTypeNode), nodesVisitor(node.arguments, visitor, isExpression));
210
+ case 200 /* SyntaxKind.ParenthesizedExpression */:
211
+ return updateParen(node, visitNode(node.expression, visitor, isExpression));
212
+ case 202 /* SyntaxKind.ArrowFunction */:
213
+ return updateArrowFunction(node, nodesVisitor(node.modifiers, visitor, isModifier), nodesVisitor(node.typeParameters, visitor, isTypeParameterDeclaration), visitParameterList(node.parameters, visitor, context, nodesVisitor), visitNode(node.type, visitor, isTypeNode), visitNode(node.equalsGreaterThanToken, tokenVisitor, isToken), visitFunctionBody(node.body, visitor, context));
214
+ case 203 /* SyntaxKind.DeleteExpression */:
215
+ return updateDelete(node, visitNode(node.expression, visitor, isExpression));
216
+ case 204 /* SyntaxKind.TypeOfExpression */:
217
+ return updateTypeOf(node, visitNode(node.expression, visitor, isExpression));
218
+ case 206 /* SyntaxKind.AwaitExpression */:
219
+ return updateAwait(node, visitNode(node.expression, visitor, isExpression));
220
+ case 207 /* SyntaxKind.PrefixUnaryExpression */:
221
+ return updatePrefix(node, visitNode(node.operand, visitor, isExpression));
222
+ case 208 /* SyntaxKind.PostfixUnaryExpression */:
223
+ return updatePostfix(node, visitNode(node.operand, visitor, isExpression));
224
+ case 209 /* SyntaxKind.BinaryExpression */:
225
+ return updateBinary(node, visitNode(node.left, visitor, isExpression), visitNode(node.right, visitor, isExpression), visitNode(node.operatorToken, tokenVisitor, isToken));
226
+ case 210 /* SyntaxKind.ConditionalExpression */:
227
+ return updateConditional(node, visitNode(node.condition, visitor, isExpression), visitNode(node.questionToken, tokenVisitor, isToken), visitNode(node.whenTrue, visitor, isExpression), visitNode(node.colonToken, tokenVisitor, isToken), visitNode(node.whenFalse, visitor, isExpression));
228
+ case 211 /* SyntaxKind.TemplateExpression */:
229
+ return updateTemplateExpression(node, visitNode(node.head, visitor, isTemplateHead), nodesVisitor(node.templateSpans, visitor, isTemplateSpan));
230
+ case 213 /* SyntaxKind.SpreadElement */:
231
+ return updateSpread(node, visitNode(node.expression, visitor, isExpression));
232
+ case 217 /* SyntaxKind.AsExpression */:
233
+ return updateAsExpression(node, visitNode(node.expression, visitor, isExpression), visitNode(node.type, visitor, isTypeNode));
234
+ case 219 /* SyntaxKind.MetaProperty */:
235
+ return updateMetaProperty(node, visitNode(node.name, visitor, isIdentifier));
236
+ // Misc
237
+ case 221 /* SyntaxKind.TemplateSpan */:
238
+ return updateTemplateSpan(node, visitNode(node.expression, visitor, isExpression), visitNode(node.literal, visitor, isTemplateMiddleOrTemplateTail));
239
+ // Element
240
+ case 223 /* SyntaxKind.Block */:
241
+ return updateBlock(node, nodesVisitor(node.statements, visitor, isStatement));
242
+ case 225 /* SyntaxKind.VariableStatement */:
243
+ return updateVariableStatement(node, nodesVisitor(node.modifiers, visitor, isModifier), visitNode(node.declarationList, visitor, isVariableDeclarationList));
244
+ case 226 /* SyntaxKind.ExpressionStatement */:
245
+ return updateExpressionStatement(node, visitNode(node.expression, visitor, isExpression));
246
+ case 227 /* SyntaxKind.IfStatement */:
247
+ return updateIf(node, visitNode(node.expression, visitor, isExpression), visitNode(node.thenStatement, visitor, isStatement, liftToBlock), visitNode(node.elseStatement, visitor, isStatement, liftToBlock));
248
+ case 228 /* SyntaxKind.DoStatement */:
249
+ return updateDo(node, visitNode(node.statement, visitor, isStatement, liftToBlock), visitNode(node.expression, visitor, isExpression));
250
+ case 229 /* SyntaxKind.WhileStatement */:
251
+ return updateWhile(node, visitNode(node.expression, visitor, isExpression), visitNode(node.statement, visitor, isStatement, liftToBlock));
252
+ case 230 /* SyntaxKind.ForStatement */:
253
+ return updateFor(node, visitNode(node.initializer, visitor, isForInitializer), visitNode(node.condition, visitor, isExpression), visitNode(node.incrementor, visitor, isExpression), visitNode(node.statement, visitor, isStatement, liftToBlock));
254
+ case 231 /* SyntaxKind.ForInStatement */:
255
+ return updateForIn(node, visitNode(node.initializer, visitor, isForInitializer), visitNode(node.expression, visitor, isExpression), visitNode(node.statement, visitor, isStatement, liftToBlock));
256
+ case 232 /* SyntaxKind.ForOfStatement */:
257
+ return updateForOf(node, visitNode(node.awaitModifier, tokenVisitor, isToken), visitNode(node.initializer, visitor, isForInitializer), visitNode(node.expression, visitor, isExpression), visitNode(node.statement, visitor, isStatement, liftToBlock));
258
+ case 235 /* SyntaxKind.ReturnStatement */:
259
+ return updateReturn(node, visitNode(node.expression, visitor, isExpression));
260
+ case 237 /* SyntaxKind.SwitchStatement */:
261
+ return updateSwitch(node, visitNode(node.expression, visitor, isExpression), visitNode(node.caseBlock, visitor, isCaseBlock));
262
+ case 239 /* SyntaxKind.ThrowStatement */:
263
+ return updateThrow(node, visitNode(node.expression, visitor, isExpression));
264
+ case 240 /* SyntaxKind.TryStatement */:
265
+ return updateTry(node, visitNode(node.tryBlock, visitor, isBlock), visitNode(node.catchClause, visitor, isCatchClause), visitNode(node.finallyBlock, visitor, isBlock));
266
+ case 242 /* SyntaxKind.VariableDeclaration */:
267
+ return updateTypeScriptVariableDeclaration(node, visitNode(node.name, visitor, isBindingName), visitNode(node.exclamationToken, tokenVisitor, isToken), visitNode(node.type, visitor, isTypeNode), visitNode(node.initializer, visitor, isExpression));
268
+ case 243 /* SyntaxKind.VariableDeclarationList */:
269
+ return updateVariableDeclarationList(node, nodesVisitor(node.declarations, visitor, isVariableDeclaration));
270
+ case 247 /* SyntaxKind.TypeAliasDeclaration */:
271
+ return updateTypeAliasDeclaration(node, nodesVisitor(node.modifiers, visitor, isModifier), visitNode(node.name, visitor, isIdentifier), nodesVisitor(node.typeParameters, visitor, isTypeParameterDeclaration), visitNode(node.type, visitor, isTypeNode));
272
+ case 249 /* SyntaxKind.ModuleDeclaration */:
273
+ return updateModuleDeclaration(node, nodesVisitor(node.modifiers, visitor, isModifier), visitNode(node.name, visitor, isIdentifier), visitNode(node.body, visitor, isModuleBody));
274
+ case 250 /* SyntaxKind.ModuleBlock */:
275
+ return updateModuleBlock(node, nodesVisitor(node.statements, visitor, isStatement));
276
+ case 251 /* SyntaxKind.CaseBlock */:
277
+ return updateCaseBlock(node, nodesVisitor(node.clauses, visitor, isCaseOrDefaultClause));
278
+ case 254 /* SyntaxKind.ImportDeclaration */:
279
+ return updateImportDeclaration(node, nodesVisitor(node.modifiers, visitor, isModifier), visitNode(node.importClause, visitor, isImportClause), visitNode(node.moduleSpecifier, visitor, isExpression));
280
+ case 255 /* SyntaxKind.ImportClause */:
281
+ return updateImportClause(node, visitNode(node.name, visitor, isIdentifier), visitNode(node.namedBindings, visitor, isNamedImportBindings), node.isTypeOnly);
282
+ case 256 /* SyntaxKind.NamespaceImport */:
283
+ return updateNamespaceImport(node, visitNode(node.name, visitor, isIdentifier));
284
+ case 262 /* SyntaxKind.NamespaceExport */:
285
+ return updateNamespaceExport(node, visitNode(node.name, visitor, isIdentifier));
286
+ case 257 /* SyntaxKind.NamedImports */:
287
+ return updateNamedImports(node, nodesVisitor(node.elements, visitor, isImportSpecifier));
288
+ case 258 /* SyntaxKind.ImportSpecifier */:
289
+ return updateImportSpecifier(node, visitNode(node.propertyName, visitor, isIdentifier), visitNode(node.name, visitor, isIdentifier));
290
+ case 259 /* SyntaxKind.ExportAssignment */:
291
+ return updateExportAssignment(node, nodesVisitor(node.modifiers, visitor, isModifier), visitNode(node.expression, visitor, isExpression));
292
+ case 260 /* SyntaxKind.ExportDeclaration */:
293
+ return updateExportDeclaration(node, nodesVisitor(node.modifiers, visitor, isModifier), visitNode(node.exportClause, visitor, isNamedExportBindings), visitNode(node.moduleSpecifier, visitor, isExpression), node.isTypeOnly);
294
+ case 261 /* SyntaxKind.NamedExports */:
295
+ return updateNamedExports(node, nodesVisitor(node.elements, visitor, isExportSpecifier));
296
+ case 263 /* SyntaxKind.ExportSpecifier */:
297
+ return updateExportSpecifier(node, visitNode(node.propertyName, visitor, isIdentifier), visitNode(node.name, visitor, isIdentifier));
298
+ // JSX
299
+ case 266 /* SyntaxKind.JsxElement */:
300
+ return updateJsxElement(node, visitNode(node.openingElement, visitor, isJsxOpeningElement), nodesVisitor(node.children, visitor, isJsxChild), visitNode(node.closingElement, visitor, isJsxClosingElement));
301
+ case 267 /* SyntaxKind.JsxSelfClosingElement */:
302
+ return updateJsxSelfClosingElement(node, visitNode(node.tagName, visitor, isJsxTagNameExpression), nodesVisitor(node.typeArguments, visitor, isTypeNode), visitNode(node.attributes, visitor, isJsxAttributes));
303
+ case 268 /* SyntaxKind.JsxOpeningElement */:
304
+ return updateJsxOpeningElement(node, visitNode(node.tagName, visitor, isJsxTagNameExpression), nodesVisitor(node.typeArguments, visitor, isTypeNode), visitNode(node.attributes, visitor, isJsxAttributes));
305
+ case 269 /* SyntaxKind.JsxClosingElement */:
306
+ return updateJsxClosingElement(node, visitNode(node.tagName, visitor, isJsxTagNameExpression));
307
+ case 270 /* SyntaxKind.JsxFragment */:
308
+ return updateJsxFragment(node, visitNode(node.openingFragment, visitor, isJsxOpeningFragment), nodesVisitor(node.children, visitor, isJsxChild), visitNode(node.closingFragment, visitor, isJsxClosingFragment));
309
+ case 273 /* SyntaxKind.JsxAttribute */:
310
+ return updateJsxAttribute(node, visitNode(node.name, visitor, isIdentifier), visitNode(node.initializer, visitor, isStringLiteralOrJsxExpression));
311
+ case 274 /* SyntaxKind.JsxAttributes */:
312
+ return updateJsxAttributes(node, nodesVisitor(node.properties, visitor, isJsxAttributeLike));
313
+ case 275 /* SyntaxKind.JsxSpreadAttribute */:
314
+ return updateJsxSpreadAttribute(node, visitNode(node.expression, visitor, isExpression));
315
+ case 276 /* SyntaxKind.JsxExpression */:
316
+ return updateJsxExpression(node, visitNode(node.expression, visitor, isExpression));
317
+ // Clauses
318
+ case 277 /* SyntaxKind.CaseClause */:
319
+ return updateCaseClause(node, visitNode(node.expression, visitor, isExpression), nodesVisitor(node.statements, visitor, isStatement));
320
+ case 278 /* SyntaxKind.DefaultClause */:
321
+ return updateDefaultClause(node, nodesVisitor(node.statements, visitor, isStatement));
322
+ case 280 /* SyntaxKind.CatchClause */:
323
+ return updateCatchClause(node, visitNode(node.variableDeclaration, visitor, isVariableDeclaration), visitNode(node.block, visitor, isBlock));
324
+ // Property assignments
325
+ case 281 /* SyntaxKind.PropertyAssignment */:
326
+ return updatePropertyAssignment(node, visitNode(node.name, visitor, isPropertyName), visitNode(node.initializer, visitor, isExpression));
327
+ case 282 /* SyntaxKind.ShorthandPropertyAssignment */:
328
+ return updateShorthandPropertyAssignment(node, visitNode(node.name, visitor, isIdentifier), visitNode(node.objectAssignmentInitializer, visitor, isExpression));
329
+ case 283 /* SyntaxKind.SpreadAssignment */:
330
+ return updateSpreadAssignment(node, visitNode(node.expression, visitor, isExpression));
331
+ // Top-level nodes
332
+ case 290 /* SyntaxKind.SourceFile */:
333
+ return updateSourceFileNode(node, visitLexicalEnvironment(node.statements, visitor, context));
334
+ // Transformation nodes
335
+ case 326 /* SyntaxKind.PartiallyEmittedExpression */:
336
+ return updatePartiallyEmittedExpression(node, visitNode(node.expression, visitor, isExpression));
337
+ case 327 /* SyntaxKind.CommaListExpression */:
338
+ return updateCommaList(node, nodesVisitor(node.elements, visitor, isExpression));
339
+ default:
340
+ // No need to visit nodes with no children.
341
+ return node;
342
+ }
343
+ }
344
+ /**
345
+ * Extracts the single node from a NodeArray.
346
+ *
347
+ * @param nodes The NodeArray.
348
+ */
349
+ function extractSingleNode(nodes) {
350
+ Debug.assert(nodes.length <= 1, "Too many nodes written to output.");
351
+ return singleOrUndefined(nodes);
352
+ }
package/package.json CHANGED
@@ -1,64 +1,36 @@
1
1
  {
2
2
  "name": "@tslite/parser",
3
- "version": "1.10.0",
4
- "description": "TSLite parser — tokenizer + Pratt parser for the TSLite language (JS subset + pipe) into ESTree",
3
+ "version": "1.12.0",
4
+ "description": "The tsc 3.9.10 parse tree, copied from the tag and cut down to the TSLite Language: the tree model, the scanner, the parser and the tree vocabulary",
5
+ "author": "Anderson D. Rosa <andersondrosa@outlook.com>",
6
+ "license": "Apache-2.0",
5
7
  "type": "module",
6
- "main": "./dist/index.cjs",
7
- "module": "./dist/index.js",
8
- "types": "./dist/index.d.ts",
9
8
  "exports": {
10
9
  ".": {
11
- "types": "./dist/index.d.ts",
12
- "import": "./dist/index.js",
13
- "require": "./dist/index.cjs"
10
+ "types": "./dist/_namespaces/ts.d.ts",
11
+ "import": "./dist/_namespaces/ts.js"
14
12
  }
15
13
  },
16
14
  "files": [
17
- "dist"
15
+ "dist",
16
+ "LICENSE",
17
+ "NOTICE"
18
18
  ],
19
- "sideEffects": false,
20
- "engines": {
21
- "node": ">=18"
19
+ "dependencies": {
20
+ "@types/microsoft__typescript-etw": "^0.1.3"
22
21
  },
23
22
  "repository": {
24
23
  "type": "git",
25
24
  "url": "https://github.com/andersondrosa/tslite.git",
26
25
  "directory": "packages/parser"
27
26
  },
28
- "keywords": [
29
- "ast",
30
- "estree",
31
- "tokenizer",
32
- "lexer",
33
- "parser",
34
- "pratt",
35
- "typescript"
36
- ],
37
- "author": "Anderson D. Rosa <andersondrosa@outlook.com>",
38
- "license": "MIT",
39
27
  "publishConfig": {
40
28
  "access": "public"
41
29
  },
42
- "dependencies": {
43
- "@tslite/ast": "^1.5.0"
44
- },
45
- "devDependencies": {
46
- "@tslite/checker": "1.9.0",
47
- "@tslite/interpret": "1.5.0",
48
- "@tslite/codegen": "1.5.0",
49
- "@tslite/capability": "1.4.0"
50
- },
51
30
  "scripts": {
52
- "build": "tsup",
53
- "dev": "tsup --watch",
54
- "test": "vitest run",
55
- "test:watch": "vitest",
56
- "test:coverage": "vitest run --coverage",
57
- "typecheck": "tsc --noEmit",
58
- "lint": "eslint src tests",
59
- "lint:fix": "eslint src tests --fix",
31
+ "build": "rm -rf dist && tsc -p tsconfig.build.json && node ../../scripts/copy-declarations.mjs dist",
60
32
  "clean": "rm -rf dist",
61
- "format": "prettier --write \"src/**/*.ts\"",
62
- "format:check": "prettier --check \"src/**/*.ts\""
33
+ "test": "vitest run",
34
+ "typecheck": "tsc --noEmit -p ."
63
35
  }
64
36
  }