@oicl-lit/analyzer 0.14.1

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 (115) hide show
  1. package/LICENSE +28 -0
  2. package/README.md +76 -0
  3. package/index.d.ts +10 -0
  4. package/index.d.ts.map +1 -0
  5. package/index.js +10 -0
  6. package/index.js.map +1 -0
  7. package/lib/analyzer.d.ts +47 -0
  8. package/lib/analyzer.d.ts.map +1 -0
  9. package/lib/analyzer.js +90 -0
  10. package/lib/analyzer.js.map +1 -0
  11. package/lib/custom-elements/custom-elements.d.ts +33 -0
  12. package/lib/custom-elements/custom-elements.d.ts.map +1 -0
  13. package/lib/custom-elements/custom-elements.js +124 -0
  14. package/lib/custom-elements/custom-elements.js.map +1 -0
  15. package/lib/custom-elements/events.d.ts +19 -0
  16. package/lib/custom-elements/events.d.ts.map +1 -0
  17. package/lib/custom-elements/events.js +25 -0
  18. package/lib/custom-elements/events.js.map +1 -0
  19. package/lib/diagnostic-code.d.ts +21 -0
  20. package/lib/diagnostic-code.d.ts.map +1 -0
  21. package/lib/diagnostic-code.js +20 -0
  22. package/lib/diagnostic-code.js.map +1 -0
  23. package/lib/errors.d.ts +24 -0
  24. package/lib/errors.d.ts.map +1 -0
  25. package/lib/errors.js +17 -0
  26. package/lib/errors.js.map +1 -0
  27. package/lib/javascript/classes.d.ts +50 -0
  28. package/lib/javascript/classes.d.ts.map +1 -0
  29. package/lib/javascript/classes.js +307 -0
  30. package/lib/javascript/classes.js.map +1 -0
  31. package/lib/javascript/functions.d.ts +31 -0
  32. package/lib/javascript/functions.d.ts.map +1 -0
  33. package/lib/javascript/functions.js +144 -0
  34. package/lib/javascript/functions.js.map +1 -0
  35. package/lib/javascript/jsdoc.d.ts +67 -0
  36. package/lib/javascript/jsdoc.d.ts.map +1 -0
  37. package/lib/javascript/jsdoc.js +244 -0
  38. package/lib/javascript/jsdoc.js.map +1 -0
  39. package/lib/javascript/mixins.d.ts +45 -0
  40. package/lib/javascript/mixins.d.ts.map +1 -0
  41. package/lib/javascript/mixins.js +147 -0
  42. package/lib/javascript/mixins.js.map +1 -0
  43. package/lib/javascript/modules.d.ts +42 -0
  44. package/lib/javascript/modules.d.ts.map +1 -0
  45. package/lib/javascript/modules.js +277 -0
  46. package/lib/javascript/modules.js.map +1 -0
  47. package/lib/javascript/packages.d.ts +18 -0
  48. package/lib/javascript/packages.d.ts.map +1 -0
  49. package/lib/javascript/packages.js +53 -0
  50. package/lib/javascript/packages.js.map +1 -0
  51. package/lib/javascript/variables.d.ts +29 -0
  52. package/lib/javascript/variables.d.ts.map +1 -0
  53. package/lib/javascript/variables.js +143 -0
  54. package/lib/javascript/variables.js.map +1 -0
  55. package/lib/lit/decorators.d.ts +36 -0
  56. package/lib/lit/decorators.d.ts.map +1 -0
  57. package/lib/lit/decorators.js +32 -0
  58. package/lib/lit/decorators.js.map +1 -0
  59. package/lib/lit/lit-element.d.ts +39 -0
  60. package/lib/lit/lit-element.d.ts.map +1 -0
  61. package/lib/lit/lit-element.js +96 -0
  62. package/lib/lit/lit-element.js.map +1 -0
  63. package/lib/lit/modules.d.ts +28 -0
  64. package/lib/lit/modules.d.ts.map +1 -0
  65. package/lib/lit/modules.js +62 -0
  66. package/lib/lit/modules.js.map +1 -0
  67. package/lib/lit/properties.d.ts +43 -0
  68. package/lib/lit/properties.d.ts.map +1 -0
  69. package/lib/lit/properties.js +268 -0
  70. package/lib/lit/properties.js.map +1 -0
  71. package/lib/lit/template.d.ts +110 -0
  72. package/lib/lit/template.d.ts.map +1 -0
  73. package/lib/lit/template.js +412 -0
  74. package/lib/lit/template.js.map +1 -0
  75. package/lib/lit-element/decorators.d.ts +11 -0
  76. package/lib/lit-element/decorators.d.ts.map +1 -0
  77. package/lib/lit-element/decorators.js +11 -0
  78. package/lib/lit-element/decorators.js.map +1 -0
  79. package/lib/lit-element/lit-element.d.ts +11 -0
  80. package/lib/lit-element/lit-element.d.ts.map +1 -0
  81. package/lib/lit-element/lit-element.js +11 -0
  82. package/lib/lit-element/lit-element.js.map +1 -0
  83. package/lib/lit-element/properties.d.ts +11 -0
  84. package/lib/lit-element/properties.d.ts.map +1 -0
  85. package/lib/lit-element/properties.js +11 -0
  86. package/lib/lit-element/properties.js.map +1 -0
  87. package/lib/model.d.ts +506 -0
  88. package/lib/model.d.ts.map +1 -0
  89. package/lib/model.js +392 -0
  90. package/lib/model.js.map +1 -0
  91. package/lib/package-analyzer.d.ts +25 -0
  92. package/lib/package-analyzer.d.ts.map +1 -0
  93. package/lib/package-analyzer.js +81 -0
  94. package/lib/package-analyzer.js.map +1 -0
  95. package/lib/paths.d.ts +24 -0
  96. package/lib/paths.d.ts.map +1 -0
  97. package/lib/paths.js +35 -0
  98. package/lib/paths.js.map +1 -0
  99. package/lib/references.d.ts +107 -0
  100. package/lib/references.d.ts.map +1 -0
  101. package/lib/references.js +345 -0
  102. package/lib/references.js.map +1 -0
  103. package/lib/types.d.ts +25 -0
  104. package/lib/types.d.ts.map +1 -0
  105. package/lib/types.js +257 -0
  106. package/lib/types.js.map +1 -0
  107. package/lib/utils.d.ts +22 -0
  108. package/lib/utils.d.ts.map +1 -0
  109. package/lib/utils.js +51 -0
  110. package/lib/utils.js.map +1 -0
  111. package/package-analyzer.d.ts +8 -0
  112. package/package-analyzer.d.ts.map +1 -0
  113. package/package-analyzer.js +8 -0
  114. package/package-analyzer.js.map +1 -0
  115. package/package.json +109 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"properties.js","sourceRoot":"","sources":["../../src/lib/lit/properties.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAWH,OAAO,EAAC,cAAc,EAAC,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAC,oBAAoB,EAAE,kBAAkB,EAAC,MAAM,iBAAiB,CAAC;AACzE,OAAO,EAAC,iBAAiB,EAAC,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAC,cAAc,EAAC,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAC,gBAAg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,EAAE,CAAC,oBAAoB,CAAC,CAAC,CAAC;IAC1B,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC;IACvB,CAAC,CAAC,IAAI,CAAC,IAAI,KAAK,IAAI,CACc,CAAC","sourcesContent":["/**\n * @license\n * Copyright 2022 Google LLC\n * SPDX-License-Identifier: BSD-3-Clause\n */\n\n/**\n * @fileoverview\n *\n * Utilities for analyzing reactive property declarations\n */\n\nimport type ts from 'typescript';\nimport {LitClassDeclaration} from './lit-element.js';\nimport {ReactiveProperty, AnalyzerInterface} from '../model.js';\nimport {getTypeForNode} from '../types.js';\nimport {getPropertyDecorator, getPropertyOptions} from './decorators.js';\nimport {hasStaticModifier} from '../utils.js';\nimport {DiagnosticCode} from '../diagnostic-code.js';\nimport {createDiagnostic} from '../errors.js';\n\nexport type TypeScript = typeof ts;\n\nexport const getProperties = (\n classDeclaration: LitClassDeclaration,\n analyzer: AnalyzerInterface\n) => {\n const {typescript: ts} = analyzer;\n const reactiveProperties = new Map<string, ReactiveProperty>();\n const undecoratedProperties = new Map<string, ts.Node>();\n\n // Filter down to just the property and getter declarations\n const propertyDeclarations = classDeclaration.members.filter(\n (m) => ts.isPropertyDeclaration(m) || ts.isGetAccessorDeclaration(m)\n ) as unknown as ts.NodeArray<ts.PropertyDeclaration>;\n\n let staticProperties;\n\n for (const prop of propertyDeclarations) {\n if (!ts.isIdentifier(prop.name) && !ts.isPrivateIdentifier(prop.name)) {\n analyzer.addDiagnostic(\n createDiagnostic({\n typescript: ts,\n node: prop,\n message:\n '@lit-labs/analyzer only supports analyzing class properties ' +\n 'named with plain identifiers, or private class fields. This ' +\n 'property was ignored: ' +\n prop.name.getText(),\n category: ts.DiagnosticCategory.Warning,\n code: DiagnosticCode.UNSUPPORTED,\n })\n );\n continue;\n }\n const name = prop.name.text;\n\n const propertyDecorator = getPropertyDecorator(ts, prop);\n if (propertyDecorator !== undefined) {\n // Decorated property; get property options from the decorator and add\n // them to the reactiveProperties map\n const options = getPropertyOptions(ts, propertyDecorator);\n reactiveProperties.set(name, {\n name,\n node: prop,\n optionsNode: options,\n type: getTypeForNode(prop, analyzer),\n attribute: getPropertyAttribute(ts, options, name),\n typeOption: getPropertyType(ts, options),\n reflect: getPropertyReflect(ts, options),\n converter: getPropertyConverter(ts, options),\n });\n } else if (name === 'properties' && hasStaticModifier(ts, prop)) {\n // This field has the static properties block (initializer or getter).\n // Note we will process this after the loop so that the\n // `undecoratedProperties` map is complete before processing the static\n // properties block.\n staticProperties = prop;\n } else if (!hasStaticModifier(ts, prop)) {\n // Store the declaration node for any undecorated properties. In a TS\n // program that happens to use a static properties block along with\n // the `declare` keyword to type the field, we can use this node to\n // get/infer the TS type of the field from\n undecoratedProperties.set(name, prop);\n }\n }\n\n // Handle static properties block (initializer or getter).\n if (staticProperties !== undefined) {\n addPropertiesFromStaticBlock(\n classDeclaration,\n staticProperties,\n undecoratedProperties,\n reactiveProperties,\n analyzer\n );\n }\n\n return reactiveProperties;\n};\n\n/**\n * Given a static properties declaration (field or getter), add property\n * options to the provided `reactiveProperties` map.\n */\nconst addPropertiesFromStaticBlock = (\n classDeclaration: LitClassDeclaration,\n properties: ts.PropertyDeclaration | ts.GetAccessorDeclaration,\n undecoratedProperties: Map<string, ts.Node>,\n reactiveProperties: Map<string, ReactiveProperty>,\n analyzer: AnalyzerInterface\n) => {\n const {typescript: ts} = analyzer;\n\n // Add any constructor initializers to the undecorated properties node map\n // from which we can infer types from. This is the primary path that JS source\n // can get their inferred types (in TS, types will come from the undecorated\n // fields passed in, since you need to declare the field to assign it in the\n // constructor).\n addConstructorInitializers(ts, classDeclaration, undecoratedProperties);\n // Find the object literal from the initializer or getter return value\n const object = getStaticPropertiesObjectLiteral(properties, analyzer);\n if (object === undefined) {\n return;\n }\n // Loop over each key/value in the object and add them to the map\n for (const prop of object.properties) {\n if (\n ts.isPropertyAssignment(prop) &&\n ts.isIdentifier(prop.name) &&\n ts.isObjectLiteralExpression(prop.initializer)\n ) {\n const name = prop.name.text;\n const options = prop.initializer;\n const nodeForType = undecoratedProperties.get(name);\n reactiveProperties.set(name, {\n name,\n node: prop,\n optionsNode: options,\n type:\n nodeForType !== undefined\n ? getTypeForNode(nodeForType, analyzer)\n : undefined,\n attribute: getPropertyAttribute(ts, options, name),\n typeOption: getPropertyType(ts, options),\n reflect: getPropertyReflect(ts, options),\n converter: getPropertyConverter(ts, options),\n });\n } else {\n analyzer.addDiagnostic(\n createDiagnostic({\n typescript: ts,\n node: prop,\n message:\n 'Unsupported static properties entry. Expected a string identifier key and object literal value.',\n code: DiagnosticCode.UNSUPPORTED,\n category: ts.DiagnosticCategory.Warning,\n })\n );\n }\n }\n};\n\n/**\n * Find the object literal for a static properties block.\n *\n * If a ts.PropertyDeclaration, it will look like:\n *\n * static properties = { ... };\n *\n * If a ts.GetAccessorDeclaration, it will look like:\n *\n * static get properties() {\n * return {... }\n * }\n */\nconst getStaticPropertiesObjectLiteral = (\n properties: ts.PropertyDeclaration | ts.GetAccessorDeclaration,\n analyzer: AnalyzerInterface\n): ts.ObjectLiteralExpression | undefined => {\n const {typescript: ts} = analyzer;\n\n let object: ts.ObjectLiteralExpression | undefined = undefined;\n if (\n ts.isPropertyDeclaration(properties) &&\n properties.initializer !== undefined &&\n ts.isObjectLiteralExpression(properties.initializer)\n ) {\n // `properties` has a static initializer; get the object from there\n object = properties.initializer;\n } else if (ts.isGetAccessorDeclaration(properties)) {\n // Object was in a static getter: find the object in the return value\n const statements = properties.body?.statements;\n const statement = statements?.[statements.length - 1];\n if (\n statement !== undefined &&\n ts.isReturnStatement(statement) &&\n statement.expression !== undefined &&\n ts.isObjectLiteralExpression(statement.expression)\n ) {\n object = statement.expression;\n }\n }\n if (object === undefined) {\n analyzer.addDiagnostic(\n createDiagnostic({\n typescript: ts,\n node: properties,\n message: `Unsupported static properties format. Expected an object literal assigned in a static initializer or returned from a static getter.`,\n code: DiagnosticCode.UNSUPPORTED,\n category: ts.DiagnosticCategory.Warning,\n })\n );\n }\n return object;\n};\n\n/**\n * Adds any field initializers in the given class's constructor to the provided\n * map. This will be used for inferring the type of fields in JS programs.\n */\nconst addConstructorInitializers = (\n ts: TypeScript,\n classDeclaration: ts.ClassDeclaration,\n undecoratedProperties: Map<string, ts.Node>\n) => {\n const ctor = classDeclaration.forEachChild((node) =>\n ts.isConstructorDeclaration(node) ? node : undefined\n );\n if (ctor !== undefined) {\n ctor.body?.statements.forEach((stmt) => {\n // Look for initializers in the form of `this.foo = xxxx`\n if (\n ts.isExpressionStatement(stmt) &&\n ts.isBinaryExpression(stmt.expression) &&\n ts.isPropertyAccessExpression(stmt.expression.left) &&\n stmt.expression.left.expression.kind === ts.SyntaxKind.ThisKeyword &&\n ts.isIdentifier(stmt.expression.left.name) &&\n !undecoratedProperties.has(stmt.expression.left.name.text)\n ) {\n // Add the initializer expression to the map\n undecoratedProperties.set(\n // Property name\n stmt.expression.left.name.text,\n // Expression from which we can infer a type\n stmt.expression.right\n );\n }\n });\n }\n};\n\n/**\n * Gets the `attribute` property of a property options object as a string.\n *\n * The attribute value returned is the value that is used at runtime by\n * ReactiveElement, not the raw option. If the attribute property option is\n * not given or is `true`, the lower-cased property name is used. If the\n * attribute property option is `false`, `undefined` is returned.\n */\nexport const getPropertyAttribute = (\n ts: TypeScript,\n optionsNode: ts.ObjectLiteralExpression | undefined,\n propertyName: string\n) => {\n if (optionsNode === undefined) {\n return propertyName.toLowerCase();\n }\n const attributeProperty = getObjectProperty(ts, optionsNode, 'attribute');\n if (attributeProperty === undefined) {\n return propertyName.toLowerCase();\n }\n const {initializer} = attributeProperty;\n if (ts.isStringLiteral(initializer)) {\n return initializer.text;\n }\n if (initializer.kind === ts.SyntaxKind.FalseKeyword) {\n return undefined;\n }\n if (\n initializer.kind === ts.SyntaxKind.TrueKeyword ||\n (ts.isIdentifier(initializer) && initializer.text === 'undefined') ||\n initializer.kind === ts.SyntaxKind.UndefinedKeyword\n ) {\n return propertyName.toLowerCase();\n }\n return undefined;\n};\n\n/**\n * Gets the `type` property of a property options object as a string.\n *\n * Note: A string is returned as a convenience so we don't have to compare\n * the type value against a known set of TS references for String, Number, etc.\n *\n * If a non-default converter is used, the types might not mean the same thing,\n * but we might not be able to realistically support custom converters.\n */\nexport const getPropertyType = (\n ts: TypeScript,\n obj: ts.ObjectLiteralExpression | undefined\n) => {\n if (obj === undefined) {\n return undefined;\n }\n const typeProperty = getObjectProperty(ts, obj, 'type');\n if (typeProperty !== undefined && ts.isIdentifier(typeProperty.initializer)) {\n return typeProperty.initializer.text;\n }\n return undefined;\n};\n\n/**\n * Gets the `reflect` property of a property options object as a boolean.\n */\nexport const getPropertyReflect = (\n ts: TypeScript,\n obj: ts.ObjectLiteralExpression | undefined\n) => {\n if (obj === undefined) {\n return false;\n }\n const reflectProperty = getObjectProperty(ts, obj, 'reflect');\n if (reflectProperty === undefined) {\n return false;\n }\n return reflectProperty.initializer.kind === ts.SyntaxKind.TrueKeyword;\n};\n\n/**\n * Gets the `converter` property of a property options object.\n */\nexport const getPropertyConverter = (\n ts: TypeScript,\n obj: ts.ObjectLiteralExpression | undefined\n) => {\n if (obj === undefined) {\n return undefined;\n }\n return getObjectProperty(ts, obj, 'converter');\n};\n\n/**\n * Gets a named property from an object literal expression.\n *\n * Only returns a value for `{k: v}` property assignments. Does not work for\n * shorthand properties (`{k}`), methods, or accessors.\n */\nconst getObjectProperty = (\n ts: TypeScript,\n obj: ts.ObjectLiteralExpression,\n name: string\n) =>\n obj.properties.find(\n (p) =>\n ts.isPropertyAssignment(p) &&\n ts.isIdentifier(p.name) &&\n p.name.text === name\n ) as ts.PropertyAssignment | undefined;\n"]}
@@ -0,0 +1,110 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2023 Google LLC
4
+ * SPDX-License-Identifier: BSD-3-Clause
5
+ */
6
+ import { type DefaultTreeAdapterTypes, type Token } from 'parse5';
7
+ import type ts from 'typescript';
8
+ export { isCommentNode, isDocumentFragment, isElementNode, isTextNode, } from '@parse5/tools';
9
+ type TypeScript = typeof ts;
10
+ export type Attribute = Token.Attribute;
11
+ export type ChildNode = DefaultTreeAdapterTypes.ChildNode;
12
+ export type CommentNode = DefaultTreeAdapterTypes.CommentNode;
13
+ export type DocumentFragment = DefaultTreeAdapterTypes.DocumentFragment;
14
+ export type Element = DefaultTreeAdapterTypes.Element;
15
+ export type Node = DefaultTreeAdapterTypes.Node;
16
+ export type TextNode = DefaultTreeAdapterTypes.TextNode;
17
+ export type ElementLocation = Token.ElementLocation;
18
+ /**
19
+ * Returns true if the given node is a tagged template expression with the
20
+ * lit-html template tag.
21
+ */
22
+ export declare const isLitHtmlTaggedTemplateExpression: (node: ts.Node, ts: TypeScript, checker: ts.TypeChecker) => node is ts.TaggedTemplateExpression;
23
+ export declare const PartType: {
24
+ readonly ATTRIBUTE: 1;
25
+ readonly CHILD: 2;
26
+ readonly PROPERTY: 3;
27
+ readonly BOOLEAN_ATTRIBUTE: 4;
28
+ readonly EVENT: 5;
29
+ readonly ELEMENT: 6;
30
+ };
31
+ export type PartType = (typeof PartType)[keyof typeof PartType];
32
+ export type PartInfo = SinglePartInfo | AttributePartInfo;
33
+ interface BasePartInfo {
34
+ valueIndex: number;
35
+ }
36
+ export interface SinglePartInfo extends BasePartInfo {
37
+ type: typeof PartType.CHILD | typeof PartType.ELEMENT;
38
+ expression: ts.Expression;
39
+ }
40
+ export interface AttributePartInfo extends BasePartInfo {
41
+ type: typeof PartType.ATTRIBUTE | typeof PartType.BOOLEAN_ATTRIBUTE | typeof PartType.PROPERTY | typeof PartType.EVENT;
42
+ prefix: string | undefined;
43
+ name: string;
44
+ strings: string[];
45
+ expressions: Array<ts.Expression>;
46
+ }
47
+ /**
48
+ * Checks if the parse5 comment node is a marker for a lit-html child part. If
49
+ * true, the node will have a `litPart` property with the part info object.
50
+ */
51
+ export declare const hasChildPart: (node: CommentNode) => node is LitTemplateCommentNode;
52
+ /**
53
+ * Retrieves the TypeScript Expression node for a parse5 comment node, if the
54
+ * comment node is a lit-html child part marker.
55
+ */
56
+ export declare const getChildPartExpression: (node: CommentNode, ts: TypeScript) => ts.Expression | undefined;
57
+ export declare const hasAttributePart: (node: Attribute) => node is LitTemplateAttribute;
58
+ export type LitTemplateNode = Node & {
59
+ litNodeIndex: number;
60
+ };
61
+ /**
62
+ * A parsed lit-html template. This extends a parse5 DocumentFragment with
63
+ * additional properties to describe the lit-html parts and the original
64
+ * TypeScript tagged-template node that the template was parsed from.
65
+ */
66
+ export interface LitTemplate extends DocumentFragment {
67
+ /**
68
+ * The original TypeScript node that this template was parsed from.
69
+ */
70
+ tsNode: ts.TaggedTemplateExpression;
71
+ /**
72
+ * The template strings that would be created from this expression at runtime.
73
+ * This is an array of strings, with the raw property set to the same array.
74
+ */
75
+ strings: TemplateStringsArray;
76
+ /**
77
+ * The template parts, including child, attribute, event, and property
78
+ * bindings.
79
+ */
80
+ parts: Array<PartInfo>;
81
+ }
82
+ export interface LitTemplateCommentNode extends CommentNode {
83
+ /**
84
+ * If this comment is a marker for a child part, this property will be set to
85
+ * the ParInfo for that part.
86
+ */
87
+ litPart?: SinglePartInfo;
88
+ /**
89
+ * The depth-first index of this node in the template.
90
+ */
91
+ litNodeIndex: number;
92
+ }
93
+ export interface LitTemplateElement extends Element {
94
+ litNodeIndex: number;
95
+ }
96
+ export interface LitTemplateAttribute extends Attribute {
97
+ litPart: PartInfo;
98
+ }
99
+ /**
100
+ * Returns all lit-html tagged template expressions in the given source file.
101
+ */
102
+ export declare const getLitTemplateExpressions: (sourceFile: ts.SourceFile, ts: TypeScript, checker: ts.TypeChecker) => Array<ts.TaggedTemplateExpression>;
103
+ /**
104
+ * Parses a lit-html tagged template expression into a {@linkcode LitTemplate}.
105
+ *
106
+ * {@linkcode LitTemplate} is a parse5 DocumentFragment with additional
107
+ * properties to describe the lit-html parts.
108
+ */
109
+ export declare const parseLitTemplate: (templateNode: ts.TaggedTemplateExpression, ts: TypeScript, _checker: ts.TypeChecker) => LitTemplate;
110
+ //# sourceMappingURL=template.d.ts.map
@@ -0,0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,kBAAmB,SAAQ,OAAO;IACjD,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,oBAAqB,SAAQ,SAAS;IACrD,OAAO,EAAE,QAAQ,CAAC;CACnB;AAKD;;GAEG;AACH,eAAO,MAAM,yBAAyB,GACpC,YAAY,EAAE,CAAC,UAAU,EACzB,IAAI,UAAU,EACd,SAAS,EAAE,CAAC,WAAW,KACtB,KAAK,CAAC,EAAE,CAAC,wBAAwB,CAYnC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,GAC3B,cAAc,EAAE,CAAC,wBAAwB,EACzC,IAAI,UAAU,EACd,UAAU,EAAE,CAAC,WAAW,KACvB,WAwQF,CAAC"}
@@ -0,0 +1,412 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2023 Google LLC
4
+ * SPDX-License-Identifier: BSD-3-Clause
5
+ */
6
+ /**
7
+ * @fileoverview
8
+ *
9
+ * Utilities for analyzing lit-html templates.
10
+ */
11
+ import { isCommentNode, isDocument, isDocumentFragment, isElementNode, traverse, } from '@parse5/tools';
12
+ import { _$LH } from 'lit-html/private-ssr-support.js';
13
+ import { parseFragment } from 'parse5';
14
+ import { isLitHtmlImportDeclaration, isResolvedPropertyAccessExpressionLitHtmlNamespace, } from './modules.js';
15
+ export { isCommentNode, isDocumentFragment, isElementNode, isTextNode, } from '@parse5/tools';
16
+ const { getTemplateHtml, marker, markerMatch, boundAttributeSuffix } = _$LH;
17
+ // TODO (justinfagnani): we have a number of template tags now:
18
+ // lit-html plain, lit-html static, lit-ssr server, preact-signals, svg,
19
+ // even the css tag. We should consider returning a template tag _type_
20
+ // to support all of them.
21
+ /**
22
+ * Returns true if the given node is a tagged template expression with the
23
+ * lit-html template tag.
24
+ */
25
+ export const isLitHtmlTaggedTemplateExpression = (node, ts, checker) => {
26
+ if (!ts.isTaggedTemplateExpression(node)) {
27
+ return false;
28
+ }
29
+ if (ts.isIdentifier(node.tag)) {
30
+ return isResolvedIdentifierLitHtmlTemplate(node.tag, ts, checker);
31
+ }
32
+ if (ts.isPropertyAccessExpression(node.tag)) {
33
+ return isResolvedPropertyAccessExpressionLitHtmlNamespace(node.tag, ts, checker);
34
+ }
35
+ return false;
36
+ };
37
+ /**
38
+ * Checks if the given node is the lit-html `html` tag function.
39
+ *
40
+ * Resolve the tag function identifier back to an import, returning true if
41
+ * the original reference was the `html` export from `lit` or `lit-html`.
42
+ *
43
+ * This check handles: aliasing and reassigning the import.
44
+ *
45
+ * ```ts
46
+ * import {html as h} from 'lit';
47
+ * h``;
48
+ * // isResolvedIdentifierLitHtmlTemplate(<h ast node>) returns true
49
+ * ```
50
+ *
51
+ * ```ts
52
+ * import {html} from 'lit-html/static.js';
53
+ * html`false`;
54
+ * // isResolvedIdentifierLitHtmlTemplate(<html ast node>) returns false
55
+ * ```
56
+ *
57
+ * @param node a TaggedTemplateExpression tag
58
+ */
59
+ const isResolvedIdentifierLitHtmlTemplate = (node, ts, checker) => {
60
+ const symbol = checker.getSymbolAtLocation(node);
61
+ if (!symbol) {
62
+ return false;
63
+ }
64
+ const templateImport = symbol.declarations?.[0];
65
+ if (!templateImport || !ts.isImportSpecifier(templateImport)) {
66
+ return false;
67
+ }
68
+ // An import specifier has the following structures:
69
+ //
70
+ // `import {<propertyName> as <name>} from <moduleSpecifier>;`
71
+ // `import {<name>} from <moduleSpecifier>;`
72
+ //
73
+ // This check allows aliasing `html` by ensuring propertyName is `html`.
74
+ // Thus `{html as myHtml}` is a valid template that can be compiled.
75
+ // Otherwise a compilable template must be a direct import of lit's `html`
76
+ // tag function.
77
+ if ((templateImport.propertyName &&
78
+ templateImport.propertyName.text !== 'html') ||
79
+ (!templateImport.propertyName && templateImport.name.text !== 'html')) {
80
+ return false;
81
+ }
82
+ const namedImport = templateImport.parent;
83
+ if (!ts.isNamedImports(namedImport)) {
84
+ return false;
85
+ }
86
+ const importClause = namedImport.parent;
87
+ if (!ts.isImportClause(importClause)) {
88
+ return false;
89
+ }
90
+ return isLitHtmlImportDeclaration(importClause.parent, ts);
91
+ };
92
+ export const PartType = {
93
+ ATTRIBUTE: 1,
94
+ CHILD: 2,
95
+ PROPERTY: 3,
96
+ BOOLEAN_ATTRIBUTE: 4,
97
+ EVENT: 5,
98
+ ELEMENT: 6,
99
+ };
100
+ /**
101
+ * Checks if the parse5 comment node is a marker for a lit-html child part. If
102
+ * true, the node will have a `litPart` property with the part info object.
103
+ */
104
+ export const hasChildPart = (node) => {
105
+ return node.litPart?.type === PartType.CHILD;
106
+ };
107
+ /**
108
+ * Retrieves the TypeScript Expression node for a parse5 comment node, if the
109
+ * comment node is a lit-html child part marker.
110
+ */
111
+ export const getChildPartExpression = (node, ts) => {
112
+ if (!hasChildPart(node)) {
113
+ return undefined;
114
+ }
115
+ const { valueIndex } = node.litPart;
116
+ let parent = node.parentNode;
117
+ while (parent && !isDocumentFragment(parent) && !isDocument(parent)) {
118
+ parent = parent.parentNode;
119
+ }
120
+ if (parent === null || isDocument(parent)) {
121
+ // Template not found. Should be error
122
+ return undefined;
123
+ }
124
+ const template = parent;
125
+ if (template.tsNode === undefined) {
126
+ // This shouldn't happen if `hasChildPart(node)` is true, but just to be
127
+ // safe...
128
+ return undefined;
129
+ }
130
+ const taggedTemplate = template.tsNode;
131
+ if (ts.isNoSubstitutionTemplateLiteral(taggedTemplate.template)) {
132
+ // Invalid case!
133
+ return undefined;
134
+ }
135
+ const { templateSpans } = taggedTemplate.template;
136
+ const span = templateSpans[valueIndex];
137
+ return span.expression;
138
+ };
139
+ export const hasAttributePart = (node) => {
140
+ return node.litPart !== undefined;
141
+ };
142
+ // Cache parsed templates by tagged template node
143
+ const templateCache = new WeakMap();
144
+ /**
145
+ * Returns all lit-html tagged template expressions in the given source file.
146
+ */
147
+ export const getLitTemplateExpressions = (sourceFile, ts, checker) => {
148
+ const templates = [];
149
+ const visitor = (tsNode) => {
150
+ if (isLitHtmlTaggedTemplateExpression(tsNode, ts, checker)) {
151
+ templates.push(tsNode);
152
+ }
153
+ ts.forEachChild(tsNode, visitor);
154
+ };
155
+ ts.forEachChild(sourceFile, visitor);
156
+ return templates;
157
+ };
158
+ /**
159
+ * Parses a lit-html tagged template expression into a {@linkcode LitTemplate}.
160
+ *
161
+ * {@linkcode LitTemplate} is a parse5 DocumentFragment with additional
162
+ * properties to describe the lit-html parts.
163
+ */
164
+ export const parseLitTemplate = (templateNode, ts, _checker) => {
165
+ const cached = templateCache.get(templateNode);
166
+ if (cached !== undefined) {
167
+ return cached;
168
+ }
169
+ const strings = getTemplateStrings(templateNode, ts);
170
+ const values = ts.isNoSubstitutionTemplateLiteral(templateNode.template)
171
+ ? []
172
+ : templateNode.template.templateSpans.map((s) => s.expression);
173
+ const templateSpans = ts.isNoSubstitutionTemplateLiteral(templateNode.template)
174
+ ? []
175
+ : templateNode.template.templateSpans;
176
+ const parts = [];
177
+ const [html, boundAttributeNames] = getTemplateHtml(strings, 1);
178
+ let spanIndex = 0;
179
+ // Index of the next bound attribute in attrNames
180
+ let boundAttributeIndex = 0;
181
+ // Depth-first node index
182
+ let nodeIndex = 0;
183
+ // Adjustments to source locations based on the difference between the
184
+ // binding expression lengths in TypeScript source vs the marker replacements
185
+ // in the prepared and parsed HTML.
186
+ // TODO (justinfagnani): implement line and column adjustments
187
+ let lineAdjust = 0;
188
+ let colAdjust = 0;
189
+ let offsetAdjust = 0;
190
+ let currentLine = 1;
191
+ const nodeMarker = `<${markerMatch}>`;
192
+ const nodeMarkerLength = nodeMarker.length;
193
+ const source = html.toString();
194
+ // TODO (justinfagnani): to support server-only templates that include
195
+ // non-fragment-parser supported tags (<html>, <body>, etc) we need to
196
+ // inspect the string and conditionally use parse() here.
197
+ const ast = parseFragment(source, { sourceCodeLocationInfo: true });
198
+ traverse(ast, {
199
+ ['pre:node'](node, _parent) {
200
+ // Adjust every node's source locations by the current adjustment values
201
+ if (node.sourceCodeLocation !== undefined) {
202
+ node.sourceCodeLocation.startOffset += offsetAdjust;
203
+ node.sourceCodeLocation.startLine += lineAdjust;
204
+ if (node.sourceCodeLocation.startLine > currentLine) {
205
+ colAdjust = 0;
206
+ currentLine = node.sourceCodeLocation.startLine;
207
+ }
208
+ else {
209
+ node.sourceCodeLocation.startCol += colAdjust;
210
+ }
211
+ }
212
+ if (isCommentNode(node)) {
213
+ if (node.data === markerMatch) {
214
+ // A child binding, like <div>${}</div>
215
+ const expression = values[spanIndex];
216
+ const span = templateSpans[spanIndex];
217
+ const spanStart = span.expression.getFullStart();
218
+ const spanEnd = span.expression.getEnd();
219
+ const spanLength = spanEnd - spanStart + 3;
220
+ // Leading whitespace of an expression is included with the
221
+ // expression. Trailing whitespace is included with the literal.
222
+ const trailingWhitespaceLength = span.literal
223
+ .getFullText()
224
+ .search(/\S|$/);
225
+ offsetAdjust +=
226
+ spanLength + trailingWhitespaceLength - nodeMarkerLength;
227
+ // Adjust line and column
228
+ const expressionText = expression.getFullText();
229
+ const expressionLines = expressionText.split(/\r?\n/);
230
+ lineAdjust += expressionLines.length - 1;
231
+ if (expressionLines.length > 1) {
232
+ colAdjust = expressionLines.at(-1).length;
233
+ }
234
+ else {
235
+ colAdjust +=
236
+ spanLength + trailingWhitespaceLength - nodeMarkerLength;
237
+ }
238
+ parts.push((node.litPart = {
239
+ type: PartType.CHILD,
240
+ valueIndex: spanIndex,
241
+ expression,
242
+ }));
243
+ spanIndex++;
244
+ }
245
+ node.litNodeIndex = nodeIndex++;
246
+ // TODO (justinfagnani): handle <!--${}--> (comment binding)
247
+ }
248
+ else if (isElementNode(node)) {
249
+ const { startTag } = node.sourceCodeLocation;
250
+ // Adjust the start tag end offset before the attributes are processed
251
+ if (startTag !== undefined) {
252
+ startTag.startOffset += offsetAdjust;
253
+ }
254
+ if (node.attrs.length > 0) {
255
+ for (const attr of node.attrs) {
256
+ const attrSourceLocation = node.sourceCodeLocation?.attrs?.[attr.name];
257
+ if (attrSourceLocation !== undefined) {
258
+ attrSourceLocation.startLine += lineAdjust;
259
+ attrSourceLocation.startCol += colAdjust;
260
+ attrSourceLocation.startOffset += offsetAdjust;
261
+ }
262
+ if (attr.name.startsWith(marker)) {
263
+ // An element binding, like <div ${}>
264
+ const expression = values[spanIndex];
265
+ const span = templateSpans[spanIndex];
266
+ const trailingWhitespaceLength = span.literal
267
+ .getFullText()
268
+ .search(/\S|$/);
269
+ offsetAdjust +=
270
+ expression.getFullText().length +
271
+ trailingWhitespaceLength -
272
+ attr.name.length +
273
+ 3;
274
+ colAdjust = offsetAdjust;
275
+ parts.push((attr.litPart = {
276
+ type: PartType.ELEMENT,
277
+ valueIndex: spanIndex,
278
+ expression,
279
+ }));
280
+ spanIndex++;
281
+ boundAttributeIndex++;
282
+ // TODO (justinfagnani): handle <div ${}="...">
283
+ }
284
+ else if (attr.name.endsWith(boundAttributeSuffix)) {
285
+ // An attribute binding, like <div foo=${}>
286
+ const [, prefix, caseSensitiveName] = /([.?@])?(.*)/.exec(boundAttributeNames[boundAttributeIndex++]);
287
+ const strings = attr.value.split(marker);
288
+ const expressions = values.slice(spanIndex, spanIndex + strings.length - 1);
289
+ // Adjust offsets
290
+ offsetAdjust -= boundAttributeSuffix.length;
291
+ colAdjust -= boundAttributeSuffix.length;
292
+ const spans = templateSpans.slice(spanIndex, spanIndex + strings.length - 1);
293
+ for (const span of spans) {
294
+ const expressionLength = span.expression.getFullWidth();
295
+ const trailingWhitespaceLength = span.literal
296
+ .getFullText()
297
+ .search(/\S|$/);
298
+ const expressionText = span.expression.getFullText();
299
+ const expressionLines = expressionText.split(/\r?\n/);
300
+ offsetAdjust +=
301
+ expressionLength +
302
+ trailingWhitespaceLength -
303
+ marker.length +
304
+ 3 /* For the ${} */;
305
+ lineAdjust += expressionLines.length - 1;
306
+ if (expressionLines.length > 1) {
307
+ colAdjust = expressionLines.at(-1).length;
308
+ }
309
+ else {
310
+ colAdjust +=
311
+ expressionLength +
312
+ trailingWhitespaceLength -
313
+ marker.length +
314
+ 3;
315
+ }
316
+ }
317
+ parts.push((attr.litPart = {
318
+ prefix,
319
+ name: caseSensitiveName,
320
+ type: prefix === '.'
321
+ ? PartType.PROPERTY
322
+ : prefix === '?'
323
+ ? PartType.BOOLEAN_ATTRIBUTE
324
+ : prefix === '@'
325
+ ? PartType.EVENT
326
+ : PartType.ATTRIBUTE,
327
+ strings,
328
+ valueIndex: spanIndex,
329
+ expressions,
330
+ }));
331
+ spanIndex += strings.length - 1;
332
+ }
333
+ if (attrSourceLocation !== undefined) {
334
+ attrSourceLocation.endLine += lineAdjust;
335
+ attrSourceLocation.endCol += colAdjust;
336
+ attrSourceLocation.endOffset += offsetAdjust;
337
+ }
338
+ }
339
+ }
340
+ // Adjust the start tag end offset after the attributes are processed
341
+ if (startTag !== undefined) {
342
+ startTag.endOffset += offsetAdjust;
343
+ }
344
+ node.litNodeIndex = nodeIndex++;
345
+ // TODO (justinfagnani): handle <${}>
346
+ }
347
+ },
348
+ node(node, _parent) {
349
+ const { sourceCodeLocation } = node;
350
+ if (sourceCodeLocation == null) {
351
+ return;
352
+ }
353
+ sourceCodeLocation.endOffset += offsetAdjust;
354
+ sourceCodeLocation.endLine += lineAdjust;
355
+ if (sourceCodeLocation.endLine > currentLine) {
356
+ colAdjust = 0;
357
+ currentLine = sourceCodeLocation.endLine;
358
+ }
359
+ else {
360
+ sourceCodeLocation.endCol += colAdjust;
361
+ }
362
+ if (isElementNode(node)) {
363
+ const { endTag } = sourceCodeLocation;
364
+ // Adjust the end tag offsets after element and its children are
365
+ // processed
366
+ if (endTag !== undefined) {
367
+ endTag.startOffset += offsetAdjust;
368
+ endTag.endOffset += offsetAdjust;
369
+ }
370
+ }
371
+ },
372
+ });
373
+ const finalAst = ast;
374
+ finalAst.parts = parts;
375
+ finalAst.strings = strings;
376
+ finalAst.tsNode = templateNode;
377
+ templateCache.set(templateNode, finalAst);
378
+ return finalAst;
379
+ };
380
+ // TODO (justinfagnani): export a traverse function that takes a visitor that
381
+ // gets passed our extended Lit interfaces. Also possibly export a unified
382
+ // traverse that can traverse TypeScript and parse5 nodes. This would allow us
383
+ // to do analysis of nested templates, for rules like "A <li> element must be a
384
+ // child of a <ul> or <ol> element", even if the <li> is in a nested template.
385
+ const getTemplateStrings = (node, ts) => {
386
+ let strings;
387
+ const { template } = node;
388
+ if (ts.isNoSubstitutionTemplateLiteral(template)) {
389
+ // The slice removes the backticks
390
+ strings = [
391
+ template.getFullText().slice(1, -1),
392
+ ];
393
+ }
394
+ else {
395
+ const spanCount = template.templateSpans.length;
396
+ strings = [
397
+ // The slice removes the opening backtick and opening ${
398
+ template.head.getFullText().slice(1, -2),
399
+ ...template.templateSpans.map((s, i) => i === spanCount - 1
400
+ ? // trimStart() removes trailing whitespace of the expression
401
+ // slice() removes the closing } and closing backtick
402
+ s.literal.getFullText().trimStart().slice(1, -1)
403
+ : // trimStart() removes trailing whitespace of the expression
404
+ // slice() removes the closing } and opening ${
405
+ s.literal.getFullText().trimStart().slice(1, -2)),
406
+ ];
407
+ }
408
+ strings.raw = strings;
409
+ Object.freeze(strings);
410
+ return strings;
411
+ };
412
+ //# sourceMappingURL=template.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"template.js","sourceRoot":"","sources":["../../src/lib/lit/template.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;GAIG;AAEH,OAAO,EACL,aAAa,EACb,UAAU,EACV,kBAAkB,EAClB,aAAa,EACb,QAAQ,GACT,MAAM,eAAe,CAAC;AACvB,OAAO,EAAC,IAAI,EAAC,MAAM,iCAAiC,CAAC;AACrD,OAAO,EAAC,aAAa,EAA2C,MAAM,QAAQ,CAAC;AAE/E,OAAO,EACL,0BAA0B,EAC1B,kDAAkD,GACnD,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,aAAa,EACb,kBAAkB,EAClB,aAAa,EACb,UAAU,GACX,MAAM,eAAe,CAAC;AAEvB,MAAM,EAAC,eAAe,EAAE,MAAM,EAAE,WAAW,EAAE,oBAAoB,EAAC,GAAG,IAAI,CAAC;AAe1E,+DAA+D;AAC/D,wEAAwE;AACxE,uEAAuE;AACvE,0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AAO,GAAG;YACR,QAAQ,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;SACD,CAAC;IACvC,CAAC;SAAM,CAAC;QACN,MAAM,SAAS,GAAG,QAAQ,CAAC,aAAa,CAAC,MAAM,CAAC;QAChD,OAAO,GAAG;YACR,wDAAwD;YACxD,QAAQ,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;YACxC,GAAG,QAAQ,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CACrC,CAAC,KAAK,SAAS,GAAG,CAAC;gBACjB,CAAC,CAAC,4DAA4D;oBAC5D,qDAAqD;oBACrD,CAAC,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,SAAS,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;gBAClD,CAAC,CAAC,4DAA4D;oBAC5D,+CAA+C;oBAC/C,CAAC,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,SAAS,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CACrD;SACiC,CAAC;IACvC,CAAC;IACA,OAAgD,CAAC,GAAG,GAAG,OAAO,CAAC;IAChE,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACvB,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC","sourcesContent":["/**\n * @license\n * Copyright 2023 Google LLC\n * SPDX-License-Identifier: BSD-3-Clause\n */\n\n/**\n * @fileoverview\n *\n * Utilities for analyzing lit-html templates.\n */\n\nimport {\n isCommentNode,\n isDocument,\n isDocumentFragment,\n isElementNode,\n traverse,\n} from '@parse5/tools';\nimport {_$LH} from 'lit-html/private-ssr-support.js';\nimport {parseFragment, type DefaultTreeAdapterTypes, type Token} from 'parse5';\nimport type ts from 'typescript';\nimport {\n isLitHtmlImportDeclaration,\n isResolvedPropertyAccessExpressionLitHtmlNamespace,\n} from './modules.js';\n\nexport {\n isCommentNode,\n isDocumentFragment,\n isElementNode,\n isTextNode,\n} from '@parse5/tools';\n\nconst {getTemplateHtml, marker, markerMatch, boundAttributeSuffix} = _$LH;\n\ntype TypeScript = typeof ts;\n\n// Why, oh why are parse5 types so weird? We re-export them to make them easier\n// to use.\nexport type Attribute = Token.Attribute;\nexport type ChildNode = DefaultTreeAdapterTypes.ChildNode;\nexport type CommentNode = DefaultTreeAdapterTypes.CommentNode;\nexport type DocumentFragment = DefaultTreeAdapterTypes.DocumentFragment;\nexport type Element = DefaultTreeAdapterTypes.Element;\nexport type Node = DefaultTreeAdapterTypes.Node;\nexport type TextNode = DefaultTreeAdapterTypes.TextNode;\nexport type ElementLocation = Token.ElementLocation;\n\n// TODO (justinfagnani): we have a number of template tags now:\n// lit-html plain, lit-html static, lit-ssr server, preact-signals, svg,\n// even the css tag. We should consider returning a template tag _type_\n// to support all of them.\n/**\n * Returns true if the given node is a tagged template expression with the\n * lit-html template tag.\n */\nexport const isLitHtmlTaggedTemplateExpression = (\n node: ts.Node,\n ts: TypeScript,\n checker: ts.TypeChecker\n): node is ts.TaggedTemplateExpression => {\n if (!ts.isTaggedTemplateExpression(node)) {\n return false;\n }\n if (ts.isIdentifier(node.tag)) {\n return isResolvedIdentifierLitHtmlTemplate(node.tag, ts, checker);\n }\n if (ts.isPropertyAccessExpression(node.tag)) {\n return isResolvedPropertyAccessExpressionLitHtmlNamespace(\n node.tag,\n ts,\n checker\n );\n }\n return false;\n};\n\n/**\n * Checks if the given node is the lit-html `html` tag function.\n *\n * Resolve the tag function identifier back to an import, returning true if\n * the original reference was the `html` export from `lit` or `lit-html`.\n *\n * This check handles: aliasing and reassigning the import.\n *\n * ```ts\n * import {html as h} from 'lit';\n * h``;\n * // isResolvedIdentifierLitHtmlTemplate(<h ast node>) returns true\n * ```\n *\n * ```ts\n * import {html} from 'lit-html/static.js';\n * html`false`;\n * // isResolvedIdentifierLitHtmlTemplate(<html ast node>) returns false\n * ```\n *\n * @param node a TaggedTemplateExpression tag\n */\nconst isResolvedIdentifierLitHtmlTemplate = (\n node: ts.Identifier,\n ts: TypeScript,\n checker: ts.TypeChecker\n): boolean => {\n const symbol = checker.getSymbolAtLocation(node);\n if (!symbol) {\n return false;\n }\n const templateImport = symbol.declarations?.[0];\n if (!templateImport || !ts.isImportSpecifier(templateImport)) {\n return false;\n }\n\n // An import specifier has the following structures:\n //\n // `import {<propertyName> as <name>} from <moduleSpecifier>;`\n // `import {<name>} from <moduleSpecifier>;`\n //\n // This check allows aliasing `html` by ensuring propertyName is `html`.\n // Thus `{html as myHtml}` is a valid template that can be compiled.\n // Otherwise a compilable template must be a direct import of lit's `html`\n // tag function.\n if (\n (templateImport.propertyName &&\n templateImport.propertyName.text !== 'html') ||\n (!templateImport.propertyName && templateImport.name.text !== 'html')\n ) {\n return false;\n }\n const namedImport = templateImport.parent;\n if (!ts.isNamedImports(namedImport)) {\n return false;\n }\n const importClause = namedImport.parent;\n if (!ts.isImportClause(importClause)) {\n return false;\n }\n return isLitHtmlImportDeclaration(importClause.parent, ts);\n};\n\nexport const PartType = {\n ATTRIBUTE: 1,\n CHILD: 2,\n PROPERTY: 3,\n BOOLEAN_ATTRIBUTE: 4,\n EVENT: 5,\n ELEMENT: 6,\n} as const;\n\nexport type PartType = (typeof PartType)[keyof typeof PartType];\n\nexport type PartInfo = SinglePartInfo | AttributePartInfo;\n\ninterface BasePartInfo {\n valueIndex: number;\n}\n\n// TODO (justinfagnani): separate into ChildPartInfo and ElementPartInfo\nexport interface SinglePartInfo extends BasePartInfo {\n type: typeof PartType.CHILD | typeof PartType.ELEMENT;\n expression: ts.Expression;\n}\n\nexport interface AttributePartInfo extends BasePartInfo {\n type:\n | typeof PartType.ATTRIBUTE\n | typeof PartType.BOOLEAN_ATTRIBUTE\n | typeof PartType.PROPERTY\n | typeof PartType.EVENT;\n prefix: string | undefined;\n name: string;\n strings: string[];\n expressions: Array<ts.Expression>;\n}\n\n/**\n * Checks if the parse5 comment node is a marker for a lit-html child part. If\n * true, the node will have a `litPart` property with the part info object.\n */\nexport const hasChildPart = (\n node: CommentNode\n): node is LitTemplateCommentNode => {\n return (node as LitTemplateCommentNode).litPart?.type === PartType.CHILD;\n};\n\n/**\n * Retrieves the TypeScript Expression node for a parse5 comment node, if the\n * comment node is a lit-html child part marker.\n */\nexport const getChildPartExpression = (node: CommentNode, ts: TypeScript) => {\n if (!hasChildPart(node)) {\n return undefined;\n }\n const {valueIndex} = node.litPart!;\n\n let parent = node.parentNode;\n while (parent && !isDocumentFragment(parent) && !isDocument(parent)) {\n parent = parent.parentNode;\n }\n if (parent === null || isDocument(parent)) {\n // Template not found. Should be error\n return undefined;\n }\n\n const template = parent as LitTemplate;\n if (template.tsNode === undefined) {\n // This shouldn't happen if `hasChildPart(node)` is true, but just to be\n // safe...\n return undefined;\n }\n const taggedTemplate = template.tsNode;\n\n if (ts.isNoSubstitutionTemplateLiteral(taggedTemplate.template)) {\n // Invalid case!\n return undefined;\n }\n const {templateSpans} = taggedTemplate.template;\n const span = templateSpans[valueIndex];\n return span.expression;\n};\n\nexport const hasAttributePart = (\n node: Attribute\n): node is LitTemplateAttribute => {\n return (node as LitTemplateAttribute).litPart !== undefined;\n};\n\nexport type LitTemplateNode = Node & {litNodeIndex: number};\n\n/**\n * A parsed lit-html template. This extends a parse5 DocumentFragment with\n * additional properties to describe the lit-html parts and the original\n * TypeScript tagged-template node that the template was parsed from.\n */\nexport interface LitTemplate extends DocumentFragment {\n /**\n * The original TypeScript node that this template was parsed from.\n */\n tsNode: ts.TaggedTemplateExpression;\n\n /**\n * The template strings that would be created from this expression at runtime.\n * This is an array of strings, with the raw property set to the same array.\n */\n strings: TemplateStringsArray;\n\n /**\n * The template parts, including child, attribute, event, and property\n * bindings.\n */\n parts: Array<PartInfo>;\n}\n\nexport interface LitTemplateCommentNode extends CommentNode {\n /**\n * If this comment is a marker for a child part, this property will be set to\n * the ParInfo for that part.\n */\n litPart?: SinglePartInfo;\n\n /**\n * The depth-first index of this node in the template.\n */\n litNodeIndex: number;\n}\n\nexport interface LitTemplateElement extends Element {\n litNodeIndex: number;\n}\n\nexport interface LitTemplateAttribute extends Attribute {\n litPart: PartInfo;\n}\n\n// Cache parsed templates by tagged template node\nconst templateCache = new WeakMap<ts.TaggedTemplateExpression, LitTemplate>();\n\n/**\n * Returns all lit-html tagged template expressions in the given source file.\n */\nexport const getLitTemplateExpressions = (\n sourceFile: ts.SourceFile,\n ts: TypeScript,\n checker: ts.TypeChecker\n): Array<ts.TaggedTemplateExpression> => {\n const templates: Array<ts.TaggedTemplateExpression> = [];\n\n const visitor = (tsNode: ts.Node) => {\n if (isLitHtmlTaggedTemplateExpression(tsNode, ts, checker)) {\n templates.push(tsNode);\n }\n ts.forEachChild(tsNode, visitor);\n };\n ts.forEachChild(sourceFile, visitor);\n\n return templates;\n};\n\n/**\n * Parses a lit-html tagged template expression into a {@linkcode LitTemplate}.\n *\n * {@linkcode LitTemplate} is a parse5 DocumentFragment with additional\n * properties to describe the lit-html parts.\n */\nexport const parseLitTemplate = (\n templateNode: ts.TaggedTemplateExpression,\n ts: TypeScript,\n _checker: ts.TypeChecker\n): LitTemplate => {\n const cached = templateCache.get(templateNode);\n if (cached !== undefined) {\n return cached;\n }\n\n const strings = getTemplateStrings(templateNode, ts);\n const values = ts.isNoSubstitutionTemplateLiteral(templateNode.template)\n ? []\n : templateNode.template.templateSpans.map((s) => s.expression);\n const templateSpans = ts.isNoSubstitutionTemplateLiteral(\n templateNode.template\n )\n ? []\n : templateNode.template.templateSpans;\n\n const parts: Array<PartInfo> = [];\n const [html, boundAttributeNames] = getTemplateHtml(strings, 1);\n\n let spanIndex = 0;\n\n // Index of the next bound attribute in attrNames\n let boundAttributeIndex = 0;\n\n // Depth-first node index\n let nodeIndex = 0;\n\n // Adjustments to source locations based on the difference between the\n // binding expression lengths in TypeScript source vs the marker replacements\n // in the prepared and parsed HTML.\n\n // TODO (justinfagnani): implement line and column adjustments\n let lineAdjust = 0;\n let colAdjust = 0;\n let offsetAdjust = 0;\n let currentLine = 1;\n\n const nodeMarker = `<${markerMatch}>`;\n const nodeMarkerLength = nodeMarker.length;\n const source = html.toString();\n\n // TODO (justinfagnani): to support server-only templates that include\n // non-fragment-parser supported tags (<html>, <body>, etc) we need to\n // inspect the string and conditionally use parse() here.\n const ast = parseFragment(source, {sourceCodeLocationInfo: true});\n\n traverse(ast, {\n ['pre:node'](node, _parent) {\n // Adjust every node's source locations by the current adjustment values\n if (node.sourceCodeLocation !== undefined) {\n node.sourceCodeLocation!.startOffset += offsetAdjust;\n node.sourceCodeLocation!.startLine += lineAdjust;\n if (node.sourceCodeLocation!.startLine > currentLine) {\n colAdjust = 0;\n currentLine = node.sourceCodeLocation!.startLine;\n } else {\n node.sourceCodeLocation!.startCol += colAdjust;\n }\n }\n\n if (isCommentNode(node)) {\n if (node.data === markerMatch) {\n // A child binding, like <div>${}</div>\n\n const expression = values[spanIndex];\n const span = templateSpans[spanIndex];\n const spanStart = span.expression.getFullStart();\n const spanEnd = span.expression.getEnd();\n const spanLength = spanEnd - spanStart + 3;\n // Leading whitespace of an expression is included with the\n // expression. Trailing whitespace is included with the literal.\n const trailingWhitespaceLength = span.literal\n .getFullText()\n .search(/\\S|$/);\n offsetAdjust +=\n spanLength + trailingWhitespaceLength - nodeMarkerLength;\n\n // Adjust line and column\n const expressionText = expression.getFullText();\n const expressionLines = expressionText.split(/\\r?\\n/);\n lineAdjust += expressionLines.length - 1;\n if (expressionLines.length > 1) {\n colAdjust = expressionLines.at(-1)!.length;\n } else {\n colAdjust +=\n spanLength + trailingWhitespaceLength - nodeMarkerLength;\n }\n\n parts.push(\n ((node as LitTemplateCommentNode).litPart = {\n type: PartType.CHILD,\n valueIndex: spanIndex,\n expression,\n } as SinglePartInfo)\n );\n spanIndex++;\n }\n (node as LitTemplateCommentNode).litNodeIndex = nodeIndex++;\n // TODO (justinfagnani): handle <!--${}--> (comment binding)\n } else if (isElementNode(node)) {\n const {startTag} = node.sourceCodeLocation as ElementLocation;\n\n // Adjust the start tag end offset before the attributes are processed\n if (startTag !== undefined) {\n startTag.startOffset += offsetAdjust;\n }\n\n if (node.attrs.length > 0) {\n for (const attr of node.attrs) {\n const attrSourceLocation =\n node.sourceCodeLocation?.attrs?.[attr.name];\n\n if (attrSourceLocation !== undefined) {\n attrSourceLocation.startLine += lineAdjust;\n attrSourceLocation.startCol += colAdjust;\n attrSourceLocation.startOffset += offsetAdjust;\n }\n\n if (attr.name.startsWith(marker)) {\n // An element binding, like <div ${}>\n\n const expression = values[spanIndex];\n const span = templateSpans[spanIndex];\n\n const trailingWhitespaceLength = span.literal\n .getFullText()\n .search(/\\S|$/);\n\n offsetAdjust +=\n expression.getFullText().length +\n trailingWhitespaceLength -\n attr.name.length +\n 3;\n colAdjust = offsetAdjust;\n\n parts.push(\n ((attr as LitTemplateAttribute).litPart = {\n type: PartType.ELEMENT,\n valueIndex: spanIndex,\n expression,\n } as SinglePartInfo)\n );\n spanIndex++;\n boundAttributeIndex++;\n // TODO (justinfagnani): handle <div ${}=\"...\">\n } else if (attr.name.endsWith(boundAttributeSuffix)) {\n // An attribute binding, like <div foo=${}>\n\n const [, prefix, caseSensitiveName] = /([.?@])?(.*)/.exec(\n boundAttributeNames[boundAttributeIndex++]!\n )!;\n const strings = attr.value.split(marker);\n const expressions = values.slice(\n spanIndex,\n spanIndex + strings.length - 1\n );\n\n // Adjust offsets\n offsetAdjust -= boundAttributeSuffix.length;\n colAdjust -= boundAttributeSuffix.length;\n\n const spans = templateSpans.slice(\n spanIndex,\n spanIndex + strings.length - 1\n );\n\n for (const span of spans) {\n const expressionLength = span.expression.getFullWidth();\n const trailingWhitespaceLength = span.literal\n .getFullText()\n .search(/\\S|$/);\n const expressionText = span.expression.getFullText();\n const expressionLines = expressionText.split(/\\r?\\n/);\n\n offsetAdjust +=\n expressionLength +\n trailingWhitespaceLength -\n marker.length +\n 3 /* For the ${} */;\n\n lineAdjust += expressionLines.length - 1;\n\n if (expressionLines.length > 1) {\n colAdjust = expressionLines.at(-1)!.length;\n } else {\n colAdjust +=\n expressionLength +\n trailingWhitespaceLength -\n marker.length +\n 3;\n }\n }\n\n parts.push(\n ((attr as LitTemplateAttribute).litPart = {\n prefix,\n name: caseSensitiveName,\n type:\n prefix === '.'\n ? PartType.PROPERTY\n : prefix === '?'\n ? PartType.BOOLEAN_ATTRIBUTE\n : prefix === '@'\n ? PartType.EVENT\n : PartType.ATTRIBUTE,\n strings,\n valueIndex: spanIndex,\n expressions,\n } as AttributePartInfo)\n );\n spanIndex += strings.length - 1;\n }\n\n if (attrSourceLocation !== undefined) {\n attrSourceLocation.endLine += lineAdjust;\n attrSourceLocation.endCol += colAdjust;\n attrSourceLocation.endOffset += offsetAdjust;\n }\n }\n }\n\n // Adjust the start tag end offset after the attributes are processed\n if (startTag !== undefined) {\n startTag.endOffset += offsetAdjust;\n }\n\n (node as LitTemplateElement).litNodeIndex = nodeIndex++;\n // TODO (justinfagnani): handle <${}>\n }\n },\n\n node(node, _parent) {\n const {sourceCodeLocation} = node;\n if (sourceCodeLocation == null) {\n return;\n }\n sourceCodeLocation.endOffset += offsetAdjust;\n sourceCodeLocation.endLine += lineAdjust;\n if (sourceCodeLocation.endLine > currentLine) {\n colAdjust = 0;\n currentLine = sourceCodeLocation!.endLine;\n } else {\n sourceCodeLocation!.endCol += colAdjust;\n }\n\n if (isElementNode(node)) {\n const {endTag} = sourceCodeLocation as ElementLocation;\n\n // Adjust the end tag offsets after element and its children are\n // processed\n if (endTag !== undefined) {\n endTag.startOffset += offsetAdjust;\n endTag.endOffset += offsetAdjust;\n }\n }\n },\n });\n\n const finalAst = ast as LitTemplate;\n finalAst.parts = parts;\n finalAst.strings = strings;\n finalAst.tsNode = templateNode;\n templateCache.set(templateNode, finalAst);\n return finalAst;\n};\n\n// TODO (justinfagnani): export a traverse function that takes a visitor that\n// gets passed our extended Lit interfaces. Also possibly export a unified\n// traverse that can traverse TypeScript and parse5 nodes. This would allow us\n// to do analysis of nested templates, for rules like \"A <li> element must be a\n// child of a <ul> or <ol> element\", even if the <li> is in a nested template.\n\nconst getTemplateStrings = (\n node: ts.TaggedTemplateExpression,\n ts: TypeScript\n) => {\n let strings: TemplateStringsArray;\n const {template} = node;\n if (ts.isNoSubstitutionTemplateLiteral(template)) {\n // The slice removes the backticks\n strings = [\n template.getFullText().slice(1, -1),\n ] as unknown as TemplateStringsArray;\n } else {\n const spanCount = template.templateSpans.length;\n strings = [\n // The slice removes the opening backtick and opening ${\n template.head.getFullText().slice(1, -2),\n ...template.templateSpans.map((s, i) =>\n i === spanCount - 1\n ? // trimStart() removes trailing whitespace of the expression\n // slice() removes the closing } and closing backtick\n s.literal.getFullText().trimStart().slice(1, -1)\n : // trimStart() removes trailing whitespace of the expression\n // slice() removes the closing } and opening ${\n s.literal.getFullText().trimStart().slice(1, -2)\n ),\n ] as unknown as TemplateStringsArray;\n }\n (strings as Mutable<TemplateStringsArray, 'raw'>).raw = strings;\n Object.freeze(strings);\n return strings;\n};\n\n/**\n * Removes the `readonly` modifier from properties in the union K.\n */\ntype Mutable<T, K extends keyof T> = Omit<T, K> & {\n -readonly [P in keyof Pick<T, K>]: P extends K ? T[P] : never;\n};\n"]}