Skip to content

Commit

Permalink
refactor(compiler): Add a kind field to the parsed AST
Browse files Browse the repository at this point in the history
The Aspirin team wants to use the output of `parseTemplate` in order to build some g3-internal tooling. However, our AST is very serialization-unfriendly.

With this change, all AST nodes now have a `kind`, and can be reasonably navigated after serialization (although the inner fields are still pretty messy).

Additionally, create a separate entrypoint that only reexports the AST nodes, so that we can control visibility on a more granular level to the AST alone.t push -f
  • Loading branch information
dylhunn committed Sep 17, 2024
1 parent 4231e8f commit e6b8293
Show file tree
Hide file tree
Showing 3 changed files with 168 additions and 43 deletions.
41 changes: 1 addition & 40 deletions packages/compiler/src/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,46 +121,7 @@ export {SourceMap} from './output/source_map';
export * from './injectable_compiler_2';
export * from './render3/partial/api';
export * from './render3/view/api';
export {
visitAll as tmplAstVisitAll,
BlockNode as TmplAstBlockNode,
BoundAttribute as TmplAstBoundAttribute,
BoundEvent as TmplAstBoundEvent,
BoundText as TmplAstBoundText,
Content as TmplAstContent,
Element as TmplAstElement,
Icu as TmplAstIcu,
Node as TmplAstNode,
Visitor as TmplAstVisitor,
RecursiveVisitor as TmplAstRecursiveVisitor,
Reference as TmplAstReference,
Template as TmplAstTemplate,
Text as TmplAstText,
TextAttribute as TmplAstTextAttribute,
Variable as TmplAstVariable,
DeferredBlock as TmplAstDeferredBlock,
DeferredBlockPlaceholder as TmplAstDeferredBlockPlaceholder,
DeferredBlockLoading as TmplAstDeferredBlockLoading,
DeferredBlockError as TmplAstDeferredBlockError,
DeferredTrigger as TmplAstDeferredTrigger,
BoundDeferredTrigger as TmplAstBoundDeferredTrigger,
IdleDeferredTrigger as TmplAstIdleDeferredTrigger,
ImmediateDeferredTrigger as TmplAstImmediateDeferredTrigger,
HoverDeferredTrigger as TmplAstHoverDeferredTrigger,
TimerDeferredTrigger as TmplAstTimerDeferredTrigger,
InteractionDeferredTrigger as TmplAstInteractionDeferredTrigger,
ViewportDeferredTrigger as TmplAstViewportDeferredTrigger,
NeverDeferredTrigger as TmplAstNeverDeferredTrigger,
SwitchBlock as TmplAstSwitchBlock,
SwitchBlockCase as TmplAstSwitchBlockCase,
ForLoopBlock as TmplAstForLoopBlock,
ForLoopBlockEmpty as TmplAstForLoopBlockEmpty,
IfBlock as TmplAstIfBlock,
IfBlockBranch as TmplAstIfBlockBranch,
DeferredBlockTriggers as TmplAstDeferredBlockTriggers,
UnknownBlock as TmplAstUnknownBlock,
LetDeclaration as TmplAstLetDeclaration,
} from './render3/r3_ast';
export * from './compiler_ast';
export * from './render3/view/t2_api';
export * from './render3/view/t2_binder';
export {createCssSelectorFromNode} from './render3/view/util';
Expand Down
50 changes: 50 additions & 0 deletions packages/compiler/src/compiler_ast.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

export {
BlockNode as TmplAstBlockNode,
BoundAttribute as TmplAstBoundAttribute,
BoundDeferredTrigger as TmplAstBoundDeferredTrigger,
BoundEvent as TmplAstBoundEvent,
BoundText as TmplAstBoundText,
Content as TmplAstContent,
Comment as TmplAstComment,
DeferredBlock as TmplAstDeferredBlock,
DeferredBlockError as TmplAstDeferredBlockError,
DeferredBlockLoading as TmplAstDeferredBlockLoading,
DeferredBlockPlaceholder as TmplAstDeferredBlockPlaceholder,
DeferredBlockTriggers as TmplAstDeferredBlockTriggers,
DeferredTrigger as TmplAstDeferredTrigger,
Element as TmplAstElement,
ForLoopBlock as TmplAstForLoopBlock,
ForLoopBlockEmpty as TmplAstForLoopBlockEmpty,
HoverDeferredTrigger as TmplAstHoverDeferredTrigger,
Icu as TmplAstIcu,
IdleDeferredTrigger as TmplAstIdleDeferredTrigger,
IfBlock as TmplAstIfBlock,
IfBlockBranch as TmplAstIfBlockBranch,
ImmediateDeferredTrigger as TmplAstImmediateDeferredTrigger,
InteractionDeferredTrigger as TmplAstInteractionDeferredTrigger,
LetDeclaration as TmplAstLetDeclaration,
NeverDeferredTrigger as TmplAstNeverDeferredTrigger,
Node as TmplAstNode,
RecursiveVisitor as TmplAstRecursiveVisitor,
Reference as TmplAstReference,
SwitchBlock as TmplAstSwitchBlock,
SwitchBlockCase as TmplAstSwitchBlockCase,
Template as TmplAstTemplate,
Text as TmplAstText,
TextAttribute as TmplAstTextAttribute,
TimerDeferredTrigger as TmplAstTimerDeferredTrigger,
UnknownBlock as TmplAstUnknownBlock,
Variable as TmplAstVariable,
ViewportDeferredTrigger as TmplAstViewportDeferredTrigger,
Visitor as TmplAstVisitor,
NodeKind as TmplAstNodeKind,
visitAll as tmplAstVisitAll,
} from './render3/r3_ast';
Loading

0 comments on commit e6b8293

Please sign in to comment.