@@ -2406,383 +2406,6 @@ export function findDecorator(kind: DecoratorKind, decorators: DecoratorNode[] |
24062406 return null ;
24072407}
24082408
2409- /** Generic AST walker. */
2410- export abstract class NodeWalker {
2411-
2412- /** Indicates whether walking has been stopped. */
2413- stopped : bool = false ;
2414-
2415- /** Visits a node and its children unless walking has been stopped. */
2416- visitNode ( node : Node | null ) : void {
2417- if ( ! node || this . stopped ) return ;
2418- if ( ! this . visit ( node ) || this . stopped ) return ;
2419- switch ( node . kind ) {
2420- case NodeKind . Source : {
2421- this . visitNodes ( ( < Source > node ) . statements ) ;
2422- break ;
2423- }
2424- case NodeKind . TypeName : {
2425- let current : TypeName | null = < TypeName > node ;
2426- while ( current ) {
2427- this . visitNode ( current . identifier ) ;
2428- current = current . next ;
2429- }
2430- break ;
2431- }
2432- case NodeKind . NamedType : {
2433- let namedType = < NamedTypeNode > node ;
2434- this . visitNode ( namedType . name ) ;
2435- this . visitNodes ( namedType . typeArguments ) ;
2436- break ;
2437- }
2438- case NodeKind . FunctionType : {
2439- let functionType = < FunctionTypeNode > node ;
2440- this . visitNodes ( functionType . explicitThisDecorators ) ;
2441- this . visitNode ( functionType . explicitThisType ) ;
2442- this . visitNodes ( functionType . parameters ) ;
2443- this . visitNode ( functionType . returnType ) ;
2444- break ;
2445- }
2446- case NodeKind . TypeParameter : {
2447- let typeParameter = < TypeParameterNode > node ;
2448- this . visitNode ( typeParameter . name ) ;
2449- this . visitNode ( typeParameter . extendsType ) ;
2450- this . visitNode ( typeParameter . defaultType ) ;
2451- break ;
2452- }
2453-
2454- case NodeKind . False :
2455- case NodeKind . Null :
2456- case NodeKind . Super :
2457- case NodeKind . This :
2458- case NodeKind . True :
2459- case NodeKind . Constructor :
2460- case NodeKind . Identifier :
2461- case NodeKind . Omitted : {
2462- break ;
2463- }
2464- case NodeKind . Assertion : {
2465- let assertion = < AssertionExpression > node ;
2466- this . visitNode ( assertion . expression ) ;
2467- this . visitNode ( assertion . toType ) ;
2468- break ;
2469- }
2470- case NodeKind . Binary : {
2471- let binary = < BinaryExpression > node ;
2472- this . visitNode ( binary . left ) ;
2473- this . visitNode ( binary . right ) ;
2474- break ;
2475- }
2476- case NodeKind . Call : {
2477- let call = < CallExpression > node ;
2478- this . visitNode ( call . expression ) ;
2479- this . visitNodes ( call . typeArguments ) ;
2480- this . visitNodes ( call . args ) ;
2481- break ;
2482- }
2483- case NodeKind . Class : {
2484- this . visitNode ( ( < ClassExpression > node ) . declaration ) ;
2485- break ;
2486- }
2487- case NodeKind . Comma : {
2488- this . visitNodes ( ( < CommaExpression > node ) . expressions ) ;
2489- break ;
2490- }
2491- case NodeKind . ElementAccess : {
2492- let elementAccess = < ElementAccessExpression > node ;
2493- this . visitNode ( elementAccess . expression ) ;
2494- this . visitNode ( elementAccess . elementExpression ) ;
2495- break ;
2496- }
2497- case NodeKind . Function : {
2498- this . visitNode ( ( < FunctionExpression > node ) . declaration ) ;
2499- break ;
2500- }
2501- case NodeKind . InstanceOf : {
2502- let instanceOf = < InstanceOfExpression > node ;
2503- this . visitNode ( instanceOf . expression ) ;
2504- this . visitNode ( instanceOf . isType ) ;
2505- break ;
2506- }
2507- case NodeKind . Literal : {
2508- let literal = < LiteralExpression > node ;
2509- switch ( literal . literalKind ) {
2510- case LiteralKind . Array : {
2511- this . visitNodes ( ( < ArrayLiteralExpression > literal ) . elementExpressions ) ;
2512- break ;
2513- }
2514- case LiteralKind . Object : {
2515- let objectLiteral = < ObjectLiteralExpression > literal ;
2516- this . visitNodes ( objectLiteral . names ) ;
2517- this . visitNodes ( objectLiteral . values ) ;
2518- break ;
2519- }
2520- case LiteralKind . Template : {
2521- let templateLiteral = < TemplateLiteralExpression > literal ;
2522- this . visitNode ( templateLiteral . tag ) ;
2523- this . visitNodes ( templateLiteral . expressions ) ;
2524- break ;
2525- }
2526- }
2527- break ;
2528- }
2529- case NodeKind . New : {
2530- let newExpression = < NewExpression > node ;
2531- this . visitNode ( newExpression . typeName ) ;
2532- this . visitNodes ( newExpression . typeArguments ) ;
2533- this . visitNodes ( newExpression . args ) ;
2534- break ;
2535- }
2536- case NodeKind . Parenthesized : {
2537- this . visitNode ( ( < ParenthesizedExpression > node ) . expression ) ;
2538- break ;
2539- }
2540- case NodeKind . PropertyAccess : {
2541- let propertyAccess = < PropertyAccessExpression > node ;
2542- this . visitNode ( propertyAccess . expression ) ;
2543- this . visitNode ( propertyAccess . property ) ;
2544- break ;
2545- }
2546- case NodeKind . Ternary : {
2547- let ternary = < TernaryExpression > node ;
2548- this . visitNode ( ternary . condition ) ;
2549- this . visitNode ( ternary . ifThen ) ;
2550- this . visitNode ( ternary . ifElse ) ;
2551- break ;
2552- }
2553- case NodeKind . UnaryPostfix : {
2554- this . visitNode ( ( < UnaryPostfixExpression > node ) . operand ) ;
2555- break ;
2556- }
2557- case NodeKind . UnaryPrefix : {
2558- this . visitNode ( ( < UnaryPrefixExpression > node ) . operand ) ;
2559- break ;
2560- }
2561-
2562- case NodeKind . Block : {
2563- this . visitNodes ( ( < BlockStatement > node ) . statements ) ;
2564- break ;
2565- }
2566- case NodeKind . Break : {
2567- this . visitNode ( ( < BreakStatement > node ) . label ) ;
2568- break ;
2569- }
2570- case NodeKind . Continue : {
2571- this . visitNode ( ( < ContinueStatement > node ) . label ) ;
2572- break ;
2573- }
2574- case NodeKind . Do : {
2575- let doStatement = < DoStatement > node ;
2576- this . visitNode ( doStatement . body ) ;
2577- this . visitNode ( doStatement . condition ) ;
2578- break ;
2579- }
2580- case NodeKind . Empty :
2581- case NodeKind . Module : {
2582- break ;
2583- }
2584- case NodeKind . ExportImport : {
2585- let exportImport = < ExportImportStatement > node ;
2586- this . visitNode ( exportImport . name ) ;
2587- this . visitNode ( exportImport . externalName ) ;
2588- break ;
2589- }
2590- case NodeKind . Export : {
2591- let exportStatement = < ExportStatement > node ;
2592- this . visitNodes ( exportStatement . members ) ;
2593- this . visitNode ( exportStatement . path ) ;
2594- break ;
2595- }
2596- case NodeKind . ExportDefault : {
2597- this . visitNode ( ( < ExportDefaultStatement > node ) . declaration ) ;
2598- break ;
2599- }
2600- case NodeKind . Expression : {
2601- this . visitNode ( ( < ExpressionStatement > node ) . expression ) ;
2602- break ;
2603- }
2604- case NodeKind . For : {
2605- let forStatement = < ForStatement > node ;
2606- this . visitNode ( forStatement . initializer ) ;
2607- this . visitNode ( forStatement . condition ) ;
2608- this . visitNode ( forStatement . incrementor ) ;
2609- this . visitNode ( forStatement . body ) ;
2610- break ;
2611- }
2612- case NodeKind . ForOf : {
2613- let forOfStatement = < ForOfStatement > node ;
2614- this . visitNode ( forOfStatement . variable ) ;
2615- this . visitNode ( forOfStatement . iterable ) ;
2616- this . visitNode ( forOfStatement . body ) ;
2617- break ;
2618- }
2619- case NodeKind . If : {
2620- let ifStatement = < IfStatement > node ;
2621- this . visitNode ( ifStatement . condition ) ;
2622- this . visitNode ( ifStatement . ifTrue ) ;
2623- this . visitNode ( ifStatement . ifFalse ) ;
2624- break ;
2625- }
2626- case NodeKind . Import : {
2627- let importStatement = < ImportStatement > node ;
2628- this . visitNodes ( importStatement . declarations ) ;
2629- this . visitNode ( importStatement . namespaceName ) ;
2630- this . visitNode ( importStatement . path ) ;
2631- break ;
2632- }
2633- case NodeKind . Return : {
2634- this . visitNode ( ( < ReturnStatement > node ) . value ) ;
2635- break ;
2636- }
2637- case NodeKind . Switch : {
2638- let switchStatement = < SwitchStatement > node ;
2639- this . visitNode ( switchStatement . condition ) ;
2640- this . visitNodes ( switchStatement . cases ) ;
2641- break ;
2642- }
2643- case NodeKind . Throw : {
2644- this . visitNode ( ( < ThrowStatement > node ) . value ) ;
2645- break ;
2646- }
2647- case NodeKind . Try : {
2648- let tryStatement = < TryStatement > node ;
2649- this . visitNodes ( tryStatement . bodyStatements ) ;
2650- this . visitNode ( tryStatement . catchVariable ) ;
2651- this . visitNodes ( tryStatement . catchStatements ) ;
2652- this . visitNodes ( tryStatement . finallyStatements ) ;
2653- break ;
2654- }
2655- case NodeKind . Variable : {
2656- let variableStatement = < VariableStatement > node ;
2657- this . visitNodes ( variableStatement . decorators ) ;
2658- this . visitNodes ( variableStatement . declarations ) ;
2659- break ;
2660- }
2661- case NodeKind . Void : {
2662- this . visitNode ( ( < VoidStatement > node ) . expression ) ;
2663- break ;
2664- }
2665- case NodeKind . While : {
2666- let whileStatement = < WhileStatement > node ;
2667- this . visitNode ( whileStatement . condition ) ;
2668- this . visitNode ( whileStatement . body ) ;
2669- break ;
2670- }
2671-
2672- case NodeKind . ClassDeclaration :
2673- case NodeKind . InterfaceDeclaration : {
2674- let classDeclaration = < ClassDeclaration > node ;
2675- this . visitDeclarationStatement ( classDeclaration ) ;
2676- this . visitNodes ( classDeclaration . typeParameters ) ;
2677- this . visitNode ( classDeclaration . extendsType ) ;
2678- this . visitNodes ( classDeclaration . implementsTypes ) ;
2679- this . visitNode ( classDeclaration . indexSignature ) ;
2680- this . visitNodes ( classDeclaration . members ) ;
2681- break ;
2682- }
2683- case NodeKind . EnumDeclaration : {
2684- let enumDeclaration = < EnumDeclaration > node ;
2685- this . visitDeclarationStatement ( enumDeclaration ) ;
2686- this . visitNodes ( enumDeclaration . values ) ;
2687- break ;
2688- }
2689- case NodeKind . EnumValueDeclaration :
2690- case NodeKind . FieldDeclaration :
2691- case NodeKind . VariableDeclaration : {
2692- this . visitVariableLikeDeclaration ( < VariableLikeDeclarationStatement > node ) ;
2693- break ;
2694- }
2695- case NodeKind . FunctionDeclaration :
2696- case NodeKind . MethodDeclaration : {
2697- let functionDeclaration = < FunctionDeclaration > node ;
2698- this . visitDeclarationStatement ( functionDeclaration ) ;
2699- this . visitNodes ( functionDeclaration . typeParameters ) ;
2700- this . visitNode ( functionDeclaration . signature ) ;
2701- this . visitNode ( functionDeclaration . body ) ;
2702- break ;
2703- }
2704- case NodeKind . ImportDeclaration : {
2705- let importDeclaration = < ImportDeclaration > node ;
2706- this . visitDeclarationStatement ( importDeclaration ) ;
2707- this . visitNode ( importDeclaration . foreignName ) ;
2708- break ;
2709- }
2710- case NodeKind . NamespaceDeclaration : {
2711- let namespaceDeclaration = < NamespaceDeclaration > node ;
2712- this . visitDeclarationStatement ( namespaceDeclaration ) ;
2713- this . visitNodes ( namespaceDeclaration . members ) ;
2714- break ;
2715- }
2716- case NodeKind . TypeDeclaration : {
2717- let typeDeclaration = < TypeDeclaration > node ;
2718- this . visitDeclarationStatement ( typeDeclaration ) ;
2719- this . visitNodes ( typeDeclaration . typeParameters ) ;
2720- this . visitNode ( typeDeclaration . type ) ;
2721- break ;
2722- }
2723-
2724- case NodeKind . Decorator : {
2725- let decorator = < DecoratorNode > node ;
2726- this . visitNode ( decorator . name ) ;
2727- this . visitNodes ( decorator . args ) ;
2728- break ;
2729- }
2730- case NodeKind . ExportMember : {
2731- let exportMember = < ExportMember > node ;
2732- this . visitNode ( exportMember . localName ) ;
2733- this . visitNode ( exportMember . exportedName ) ;
2734- break ;
2735- }
2736- case NodeKind . Parameter : {
2737- let parameter = < ParameterNode > node ;
2738- this . visitNodes ( parameter . decorators ) ;
2739- this . visitNode ( parameter . name ) ;
2740- this . visitNode ( parameter . type ) ;
2741- this . visitNode ( parameter . initializer ) ;
2742- break ;
2743- }
2744- case NodeKind . SwitchCase : {
2745- let switchCase = < SwitchCase > node ;
2746- this . visitNode ( switchCase . label ) ;
2747- this . visitNodes ( switchCase . statements ) ;
2748- break ;
2749- }
2750- case NodeKind . IndexSignature : {
2751- let indexSignature = < IndexSignatureNode > node ;
2752- this . visitNode ( indexSignature . keyType ) ;
2753- this . visitNode ( indexSignature . valueType ) ;
2754- break ;
2755- }
2756- default : assert ( false ) ;
2757- }
2758- }
2759-
2760- /** Visits a declaration statement's common children. */
2761- protected visitDeclarationStatement ( node : DeclarationStatement ) : void {
2762- this . visitNode ( node . name ) ;
2763- this . visitNodes ( node . decorators ) ;
2764- }
2765-
2766- /** Visits a variable-like declaration statement's common children. */
2767- protected visitVariableLikeDeclaration ( node : VariableLikeDeclarationStatement ) : void {
2768- this . visitDeclarationStatement ( node ) ;
2769- this . visitNode ( node . type ) ;
2770- this . visitNode ( node . initializer ) ;
2771- }
2772-
2773- /** Visits a possibly-null array of nodes. */
2774- protected visitNodes < T extends Node > ( nodes : T [ ] | null ) : void {
2775- if ( ! nodes || this . stopped ) return ;
2776- for ( let i = 0 , k = nodes . length ; i < k ; ++ i ) {
2777- this . visitNode ( nodes [ i ] ) ;
2778- if ( this . stopped ) break ;
2779- }
2780- }
2781-
2782- /** Called for each visited node. Return `false` to skip its children. */
2783- abstract visit ( node : Node ) : bool ;
2784- }
2785-
27862409/** Mangles an external to an internal path. */
27872410export function mangleInternalPath ( path : string ) : string {
27882411 if ( path . endsWith ( "/" ) ) {
0 commit comments