@arcgis/lumina-compiler 4.31.0-next.100

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 (142) hide show
  1. package/LICENSE.md +13 -0
  2. package/README.md +21 -0
  3. package/dist/chunk-BQ4U6HQL.js +1 -0
  4. package/dist/chunk-JFKSI6I7.js +1 -0
  5. package/dist/context/index.d.ts +241 -0
  6. package/dist/context/types.d.ts +34 -0
  7. package/dist/context/utils.d.ts +23 -0
  8. package/dist/context/utils.spec.d.ts +1 -0
  9. package/dist/defaultAssetsUrl.d.ts +21 -0
  10. package/dist/defaultAssetsUrl.spec.d.ts +1 -0
  11. package/dist/dependencies/arcgisCore.d.ts +30 -0
  12. package/dist/dependencies/discover.d.ts +62 -0
  13. package/dist/dependencies/index.d.ts +11 -0
  14. package/dist/dependencies/lit.d.ts +2 -0
  15. package/dist/dependencies/loaders.d.ts +8 -0
  16. package/dist/dependencies/stencil.d.ts +6 -0
  17. package/dist/dependencies/testSetupFiles.d.ts +21 -0
  18. package/dist/dependencies/updateLumina.d.ts +8 -0
  19. package/dist/dependencies/updateLumina.spec.d.ts +1 -0
  20. package/dist/dependencies/utils.d.ts +23 -0
  21. package/dist/entrypoints/addNonLazyImports.d.ts +13 -0
  22. package/dist/entrypoints/config.d.ts +23 -0
  23. package/dist/entrypoints/dtsUtils.d.ts +22 -0
  24. package/dist/entrypoints/dtsUtils.spec.d.ts +1 -0
  25. package/dist/entrypoints/findUtils.d.ts +21 -0
  26. package/dist/entrypoints/findUtils.spec.d.ts +1 -0
  27. package/dist/entrypoints/handleComponentImports.d.ts +13 -0
  28. package/dist/entrypoints/pathMapping.d.ts +25 -0
  29. package/dist/entrypoints/resolveTagName.d.ts +14 -0
  30. package/dist/entrypoints/resolveTagName.spec.d.ts +1 -0
  31. package/dist/frameworkTypes/index.d.ts +15 -0
  32. package/dist/frameworkTypes/lumina.d.ts +5 -0
  33. package/dist/frameworkTypes/preact.d.ts +6 -0
  34. package/dist/frameworkTypes/react.d.ts +6 -0
  35. package/dist/frameworkTypes/stencil.d.ts +5 -0
  36. package/dist/frameworkTypes/utils.d.ts +8 -0
  37. package/dist/frameworkTypes/vanilla.d.ts +3 -0
  38. package/dist/index.d.ts +29 -0
  39. package/dist/index.js +248 -0
  40. package/dist/jsxToLitHtml/autoAddNothing.d.ts +8 -0
  41. package/dist/jsxToLitHtml/comments.d.ts +19 -0
  42. package/dist/jsxToLitHtml/config.d.ts +148 -0
  43. package/dist/jsxToLitHtml/convertProps.d.ts +10 -0
  44. package/dist/jsxToLitHtml/escapeForTemplateLiteral.d.ts +45 -0
  45. package/dist/jsxToLitHtml/imports.d.ts +32 -0
  46. package/dist/jsxToLitHtml/index.d.ts +17 -0
  47. package/dist/jsxToLitHtml/inferPropType.d.ts +40 -0
  48. package/dist/jsxToLitHtml/insertRepeatCall.d.ts +49 -0
  49. package/dist/jsxToLitHtml/jsxVisitor.d.ts +11 -0
  50. package/dist/jsxToLitHtml/templateParts.d.ts +17 -0
  51. package/dist/jsxToLitHtml/throwOnImportingExternalized.d.ts +10 -0
  52. package/dist/jsxToLitHtml/types.d.ts +80 -0
  53. package/dist/jsxToLitHtml/utils.d.ts +14 -0
  54. package/dist/jsxToLitHtml/utils.spec.d.ts +1 -0
  55. package/dist/manifests/complexTypes/addComponentMetadata.d.ts +5 -0
  56. package/dist/manifests/complexTypes/addMethodMetadata.d.ts +6 -0
  57. package/dist/manifests/complexTypes/addPropMetadata.d.ts +8 -0
  58. package/dist/manifests/complexTypes/docsUtils.d.ts +18 -0
  59. package/dist/manifests/complexTypes/event.d.ts +9 -0
  60. package/dist/manifests/complexTypes/getComplexPropertyType.d.ts +11 -0
  61. package/dist/manifests/complexTypes/transformUtils.d.ts +130 -0
  62. package/dist/manifests/complexTypes/transformUtils.spec.d.ts +1 -0
  63. package/dist/manifests/complexTypes/typeToEnum.d.ts +14 -0
  64. package/dist/manifests/complexTypes/typeToEnum.spec.d.ts +1 -0
  65. package/dist/manifests/complexTypes/types.d.ts +135 -0
  66. package/dist/manifests/config.d.ts +2 -0
  67. package/dist/manifests/createManifest.d.ts +39 -0
  68. package/dist/manifests/customElementDecoratorPlugins.d.ts +58 -0
  69. package/dist/manifests/customElementDecoratorPlugins.spec.d.ts +1 -0
  70. package/dist/manifests/hideUntilHydrated.d.ts +15 -0
  71. package/dist/manifests/index.d.ts +12 -0
  72. package/dist/manifests/kebabCaseAttributes.d.ts +18 -0
  73. package/dist/manifests/lazy.d.ts +22 -0
  74. package/dist/manifests/lazy.spec.d.ts +1 -0
  75. package/dist/manifests/stencilManifest.d.ts +17 -0
  76. package/dist/manifests/storybookManifest.d.ts +6 -0
  77. package/dist/manifests/types.d.ts +1 -0
  78. package/dist/manifests/utils.d.ts +17 -0
  79. package/dist/plugins/buildCdn.d.ts +14 -0
  80. package/dist/plugins/buildStencilHydrate.d.ts +16 -0
  81. package/dist/plugins/buildWrappers.d.ts +3 -0
  82. package/dist/plugins/configureVite.d.ts +19 -0
  83. package/dist/plugins/externalizeDependencies.d.ts +34 -0
  84. package/dist/plugins/externalizeDependencies.spec.d.ts +1 -0
  85. package/dist/plugins/generateDocs.d.ts +10 -0
  86. package/dist/plugins/handleDynamicAssets.d.ts +3 -0
  87. package/dist/plugins/handleStaticAssets.d.ts +9 -0
  88. package/dist/plugins/loadLitCss.d.ts +89 -0
  89. package/dist/plugins/printTotalBuildSize.d.ts +7 -0
  90. package/dist/plugins/provideAssets.d.ts +53 -0
  91. package/dist/plugins/provideAssets.spec.d.ts +1 -0
  92. package/dist/plugins/setAssetsPath.d.ts +10 -0
  93. package/dist/plugins/updatePackageJson.d.ts +9 -0
  94. package/dist/plugins/updatePackageJson.spec.d.ts +1 -0
  95. package/dist/publicTypes.d.ts +626 -0
  96. package/dist/puppeteer-testing/globalSetup.d.ts +72 -0
  97. package/dist/puppeteer-testing/globalSetup.js +11 -0
  98. package/dist/puppeteer-testing/index.d.ts +9 -0
  99. package/dist/puppeteer-testing/index.js +6 -0
  100. package/dist/puppeteer-testing/injected.d.ts +8 -0
  101. package/dist/puppeteer-testing/puppeteer/browser.d.ts +6 -0
  102. package/dist/puppeteer-testing/puppeteer/element.d.ts +219 -0
  103. package/dist/puppeteer-testing/puppeteer/events.d.ts +21 -0
  104. package/dist/puppeteer-testing/puppeteer/page.d.ts +5 -0
  105. package/dist/puppeteer-testing/puppeteer/types.d.ts +124 -0
  106. package/dist/puppeteer-testing/vitest/matchers/attributes.d.ts +4 -0
  107. package/dist/puppeteer-testing/vitest/matchers/classList.d.ts +4 -0
  108. package/dist/puppeteer-testing/vitest/matchers/events.d.ts +7 -0
  109. package/dist/puppeteer-testing/vitest/matchers/index.d.ts +38 -0
  110. package/dist/puppeteer-testing/vitest/matchers/text.d.ts +2 -0
  111. package/dist/puppeteer-testing/vitest/matchers/utils.d.ts +1 -0
  112. package/dist/puppeteer-testing/vitest/runner.d.ts +15 -0
  113. package/dist/puppeteer-testing/vitest/setupFile.d.ts +1 -0
  114. package/dist/testing/index.d.ts +11 -0
  115. package/dist/testing/index.js +1 -0
  116. package/dist/testing/mount.d.ts +106 -0
  117. package/dist/testing/setupFile.d.ts +1 -0
  118. package/dist/testing/snapshotSerializer.d.ts +12 -0
  119. package/dist/testing/wrapController.d.ts +33 -0
  120. package/dist/tests/utils.d.ts +4 -0
  121. package/dist/transformers/guardAgainstInternalJsDoc.d.ts +11 -0
  122. package/dist/transformers/index.d.ts +22 -0
  123. package/dist/transformers/injectRuntimeOptions.d.ts +3 -0
  124. package/dist/transformers/internalTypeScriptApis.d.ts +29 -0
  125. package/dist/transformers/liftDecorators.d.ts +21 -0
  126. package/dist/transformers/members.d.ts +12 -0
  127. package/dist/transformers/property.d.ts +9 -0
  128. package/dist/transformers/propertyOptions.d.ts +111 -0
  129. package/dist/transformers/updateOriginalFile.d.ts +20 -0
  130. package/dist/transformers/utils.d.ts +14 -0
  131. package/dist/types/astTransformers.d.ts +3 -0
  132. package/dist/types/hideInternalLitElement.d.ts +9 -0
  133. package/dist/types/index.d.ts +18 -0
  134. package/dist/types/liftSetterTypes.d.ts +33 -0
  135. package/dist/types/textTransformers.d.ts +4 -0
  136. package/dist/types/transformComponentMembers.d.ts +10 -0
  137. package/dist/useLumina.d.ts +13 -0
  138. package/dist/utils/error.d.ts +4 -0
  139. package/dist/utils/packageJson.d.ts +24 -0
  140. package/dist/utils/path.d.ts +25 -0
  141. package/dist/utils/path.spec.d.ts +1 -0
  142. package/package.json +80 -0
@@ -0,0 +1,148 @@
1
+ export declare const fragmentName = "Fragment";
2
+ export declare const dynamicHtmlTagName = "DynamicHtmlTag";
3
+ export declare const dynamicSvgTagName = "DynamicSvgTag";
4
+ /**
5
+ * Using symbols rather than strings for these so that the type system forces us
6
+ * to handle the dynamic tag name case.
7
+ */
8
+ export declare const dynamicHtmlSymbol: unique symbol;
9
+ export declare const dynamicSvgSymbol: unique symbol;
10
+ /**
11
+ * When Stencil encounters a JSX prop like "onArcgisClick", it converts the
12
+ * first letter of the event name ("ArcgisClick") to lower case, and takes the
13
+ * rest as is ("arcgisClick").
14
+ *
15
+ * But, Preact, React 19 and Lit (Lit JSX in turn) don't do any case
16
+ * conversion so you have to use "onarcgisClick" instead.
17
+ *
18
+ * This means, if you are consuming web component authored in Stencil, it's
19
+ * JSX typings may wrongly include properties like "onArcgisClick" rather
20
+ * than "onarcgisClick".
21
+ *
22
+ * When consuming Stencil typings in a Lit project, we are creating a mapped
23
+ * type that fixes the casing difference. But just in case any place slips
24
+ * through, this flag is used to normalize the casing.
25
+ */
26
+ export declare const shouldNormalizeCustomElementEventCasing = true;
27
+ /**
28
+ * Always set these properties as attributes on all elements
29
+ */
30
+ export declare const alwaysAttributes: Set<string>;
31
+ /**
32
+ * Always set these properties as attributes on non-custom-elements
33
+ */
34
+ export declare const nativeAlwaysAttributes: Set<string>;
35
+ /**
36
+ * These don't exist as a property, only as an attribute
37
+ */
38
+ export declare const htmlAlwaysAttributes: Record<string, Set<string>>;
39
+ /**
40
+ * The mappings between native DOM property and the equivalent attribute it
41
+ * reflects to.
42
+ *
43
+ * This list was generated using the ./extractPropertyToAttributeMappings.js
44
+ * script.
45
+ *
46
+ */
47
+ type PropertyToAttributeMappings = {
48
+ /**
49
+ * Mappings that are common to all HTML elements
50
+ */
51
+ common: ElementPropertyToAttributeMappings;
52
+ /**
53
+ * Mappings that are specific to a given HTML element
54
+ */
55
+ perElement: Record<string, ElementPropertyToAttributeMappings | undefined>;
56
+ };
57
+ export type ElementPropertyToAttributeMappings = {
58
+ /**
59
+ * This list is only used to apply an optional performance optimization.
60
+ * If it gets out of date or is missing some properties, it's not a big deal.
61
+ *
62
+ * This list is used to convert JSX properties with static values to
63
+ * equivalent attributes.
64
+ *
65
+ * Thus instead of `.property=${"1"}` final lit-html looks like `attribute=1`.
66
+ * Since static attributes are just part of the HTML string and not a special
67
+ * binding, lit-html doesn't have to waste time diffing them on re-render.
68
+ */
69
+ normal?: Record<string, string | undefined>;
70
+ /**
71
+ * Unfortunately, for many DOM **properties**, when set to undefined
72
+ * (`el.autocapitalize = undefined`), rather than removing the attribute, they
73
+ * set the attribute to an `"undefined"` string. This is never a desirable
74
+ * outcome. This is the web platform behavior.
75
+ *
76
+ * lit-html also has an anti-feature of rendering `undefined` **attribute**
77
+ * values as `"undefined"` strings (they wanted to mirror the `.setAttribute()`
78
+ * behavior).
79
+ *
80
+ * Thus, the only way to unset such attributes in lit-html is to use attribute
81
+ * rather than property, and then add `?? nothing` to the attribute value.
82
+ * `nothing` is a special magic value Lit had to invent to mean
83
+ * "removeAttribute()"
84
+ *
85
+ * Note, we can not use `?? nothing` with property bindings because of
86
+ * https://github.com/lit/lit/issues/4760
87
+ */
88
+ stringified?: Record<string, string | undefined>;
89
+ };
90
+ export declare const propertyToAttributeMappings: PropertyToAttributeMappings;
91
+ export declare const htmlAlwaysBooleanAttributes: Set<string>;
92
+ /**
93
+ * List of all DOM events settable in JSX. These event names are converted to
94
+ * lowercase. All others are left as authored as we can't make assumptions about
95
+ * what was the intended casing.
96
+ */
97
+ export declare const nativeEvents: Set<string>;
98
+ /**
99
+ * HTML elements that do not have children and closing tags
100
+ *
101
+ * Based on https://developer.mozilla.org/en-US/docs/Glossary/Void_element
102
+ */
103
+ export declare const voidElements: Set<string>;
104
+ /**
105
+ * Elements for which the `svg` function needs to be used rather than `html`.
106
+ *
107
+ * @example
108
+ * ```tsx
109
+ * <svg>
110
+ * <circle />
111
+ * </svg>
112
+ * ```
113
+ *
114
+ * Is converted into:
115
+ * ```ts
116
+ * html`<svg>${svg`<circle />`}</svg>`
117
+ * ```
118
+ *
119
+ * (foreign elements in HTML can be self-closing)
120
+ */
121
+ export declare const svgElements: Set<string>;
122
+ /**
123
+ * Elements for which the `math` function needs to be used rather than `html`
124
+ *
125
+ * @example
126
+ * ```tsx
127
+ * <math>
128
+ * <mn>6</mn>
129
+ * </math>
130
+ * ```
131
+ *
132
+ * Is converted into:
133
+ * ```ts
134
+ * html`<math>${mathml`<mn>6</mn>`}</math>`
135
+ * ```
136
+ *
137
+ * (foreign elements in HTML can be self-closing)
138
+ */
139
+ export declare const mathMlElements: Set<string>;
140
+ /**
141
+ * Although most native elements do not contain dashes inside, there are a
142
+ * few exceptions. Explicitly declaring a custom element by this name is
143
+ * forbidden
144
+ *
145
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/CustomElementRegistry/define#valid_custom_element_names
146
+ */
147
+ export declare const blockListedCustomElementNames: Set<string>;
148
+ export {};
@@ -0,0 +1,10 @@
1
+ import ts from "typescript";
2
+ import type { TemplatePart } from "./templateParts";
3
+ import type { JsxContext } from "./types";
4
+ import type { JsxPropType } from "./inferPropType";
5
+ import { type dynamicHtmlSymbol, type dynamicSvgSymbol } from "./config";
6
+ /**
7
+ * Handle the conversion for each JSX prop type
8
+ */
9
+ export declare const convertProps: Record<JsxPropType, (context: JsxContext, initializer: ts.JsxAttributeValue | undefined, propName: string, tagName: string | typeof dynamicHtmlSymbol | typeof dynamicSvgSymbol) => TemplatePart[]>;
10
+ export declare function keyInitializerToExpression(initializer: ts.JsxAttributeValue | undefined): ts.Expression;
@@ -0,0 +1,45 @@
1
+ /**
2
+ * This file is a workaround for a TypeScript bug:
3
+ * https://github.com/microsoft/TypeScript/issues/59150
4
+ *
5
+ * Once that bug is fixed, the code can be simplified like so:
6
+ * - This file can be removed
7
+ * - For each place where `escapeBackticks` or `escapeForTemplateLiteral` was
8
+ * used and the result was passed as the 1st AND 2nd parameter to one of
9
+ * ts.factory.createNoSubstitutionTemplateLiteral,
10
+ * ts.factory.createTemplateHead, ts.factory.createTemplateMiddle, or
11
+ * ts.factory.createTemplateTail, change those places like so:
12
+ * - DO NOT call `escapeBackticks` or `escapeForTemplateLiteral` anymore -
13
+ * pass the value as is.
14
+ * - DO NOT provide the 2nd parameter to the factory function.
15
+ * - If `escapeForTemplateLiteral` was used in some other place, it can
16
+ * potentially be replaced with a function like this:
17
+ * string=>escapeTemplateSubstitution(string).replaceAll('`','\`')
18
+ * (where escapeTemplateSubstitution is defined in the current file - move it)
19
+ *
20
+ * More details:
21
+ *
22
+ * In template literals, even though we *really* only need to escape ${ and
23
+ * backticks, we are escaping non-ASCII characters too as that improves scanner
24
+ * performance in JavaScript engines.
25
+ *
26
+ * This is what esbuild does (https://esbuild.github.io/api/#charset), what
27
+ * V8 recommends (https://v8.dev/blog/scanner) and what TypeScript does.
28
+ *
29
+ * The code in this file has been copied from TypeScript's code for escaping
30
+ * template literals (but simplified to remove dead branches and fix eslint
31
+ * warnings):
32
+ * https://github.com/microsoft/TypeScript/blob/3163fe7e3898c1f48cd9bc097b96e3426cd2a453/src/compiler/utilities.ts#L5918-L5986
33
+ *
34
+ * TypeScript can automatically escape template literals for us, but we opt out
35
+ * of that as, due to a bug, they also escape new line characters which is not
36
+ * good as it decreases readability when debugging code.
37
+ *
38
+ * TypeScript does not expose the template literal escaping utils so we had
39
+ * to copy the code here, but modify to not escape new lines.
40
+ *
41
+ */
42
+ declare function escapeNonAsciiString(s: string): string;
43
+ export declare const escapeBackticks: typeof escapeNonAsciiString;
44
+ export declare const escapeTemplateSubstitution: (str: string) => string;
45
+ export {};
@@ -0,0 +1,32 @@
1
+ import ts from "typescript";
2
+ import { type JsxContext } from "./types";
3
+ /**
4
+ * This runs before we know what imports will be needed.
5
+ *
6
+ * 1. Go though all import paths and take note of them to inform us later if
7
+ * some custom element import still need or need not be added
8
+ * 2. Take note of all the existing Lit imports. Otherwise, when inserting
9
+ * imports, if we see that e.x "html" is not present in the "lit" import, we
10
+ * might import it again and fail to check that it might be imported further
11
+ * down from "lit-html".
12
+ */
13
+ export declare function trackExistingImports(context: JsxContext, importDeclaration: ts.ImportDeclaration): ts.ImportDeclaration;
14
+ /**
15
+ * After we know what imports will be needed, if there already are some imports
16
+ * from the places we are looking for, augment those import declarations.
17
+ *
18
+ * In a step after this, if any imports will still be needed, we will add them.
19
+ *
20
+ * @remarks
21
+ * We don't bother removing `@arcgis/lumina` "h" and "Fragment" imports as those
22
+ * would be removed by rollup if there are no usages outside of JSX. If
23
+ * those are explicitly called outside of jsx, Rollup will throw a build time
24
+ * error (since `@arcgis/lumina` does not actually define h and Fragment but only
25
+ * declare their typings).
26
+ */
27
+ export declare function augmentExistingImports(this: JsxContext, node: ts.Statement): ts.Statement;
28
+ /**
29
+ * For each remaining needed import that is not already included, add an
30
+ * import declaration
31
+ */
32
+ export declare function addMissingLitImports(context: JsxContext): ts.ImportDeclaration[];
@@ -0,0 +1,17 @@
1
+ import type { FileTransformer } from "../publicTypes";
2
+ /**
3
+ * Let developers author components in JSX for better type checking and developer
4
+ * experience, but convert JSX to lit-html at build time for better performance.
5
+ *
6
+ * This TypeScript transformer converts JSX expressions to lit-html tagged
7
+ * literals, adding necessary imports in the process
8
+ *
9
+ * @remarks
10
+ * If you wish to explicitly opt-out of JSX to lit-html transform in a given
11
+ * file, you can do so by specifying a `@jsx` pragma at the top of the file.
12
+ * For example, to use React JSX in a file, add the following at the top:
13
+ * ```ts
14
+ * /** @jsx React.createElement *\/
15
+ * ```
16
+ */
17
+ export declare const transformJsxToLitHtml: FileTransformer;
@@ -0,0 +1,40 @@
1
+ import ts from "typescript";
2
+ import { dynamicHtmlSymbol, dynamicSvgSymbol } from "./config";
3
+ /**
4
+ * Check if prop initializer has bindProperty(), bindAttribute(),
5
+ * bindBooleanAttribute() or bindEvent() call - these explicitly indicate the
6
+ * prop type.
7
+ *
8
+ * @remarks
9
+ * Not checking for now if function is actually coming from `@arcgis/lumina` - if
10
+ * this is an issue, can add later
11
+ */
12
+ export declare function checkExplicitPropType(initializer: ts.JsxAttributeValue | undefined): {
13
+ readonly propType: JsxPropType;
14
+ readonly initializer: ts.JsxExpression | undefined;
15
+ } | undefined;
16
+ /**
17
+ * Decide whether a JSX prop should be converted to property, attribute or event
18
+ *
19
+ * Unless there is a good reason to do otherwise, most props are converted into
20
+ * properties rather than attributes. Reasons:
21
+ * - For third-party web components, since we are consuming them in JSX, the
22
+ * typings will most likely include names of properties not attributes.
23
+ * - Setting attributes is more bug-prone in lit as `a=${undefined}` is still
24
+ * considered truthy (you have to use `a=${nothing}` to unset an attribute)
25
+ * - If you want to conditionally display a boolean html attribute, there is
26
+ * the `?a=${someBoolean}` syntax.
27
+ * - The above two cases add complexity and bugs - properties are much simpler
28
+ * - Setting property is more performant than setting attribute
29
+ *
30
+ * For most HTML attributes, setting the property will reflect to the attribute.
31
+ * If the third-party web component expects to have the attribute set (for
32
+ * styling or other reasons), it should reflect the property.
33
+ * There are also flag functions available (bindAttribute and etc) if you
34
+ * explicitly want to overwrite the below prop type inference logic.
35
+ */
36
+ export declare function inferPropType(propName: string, initializer: ts.JsxAttributeValue | undefined, tagName: string | typeof dynamicHtmlSymbol | typeof dynamicSvgSymbol): JsxPropType;
37
+ declare const specialPropsArray: readonly ["class", "style", "ref", "directives", "key"];
38
+ type SpecialProp = (typeof specialPropsArray)[number];
39
+ export type JsxPropType = SpecialProp | "attribute" | "booleanAttribute" | "event" | "property";
40
+ export {};
@@ -0,0 +1,49 @@
1
+ import ts from "typescript";
2
+ import type { JsxContext } from "./types";
3
+ /**
4
+ * By default, when we see a `key=""` prop, we convert it like this:
5
+ * ```tsx
6
+ * // before:
7
+ * <div key="value" />
8
+ * // after:
9
+ * keyed('value', html`<div></div>`);
10
+ * ```
11
+ *
12
+ * However, when mapping over items, if key was provided, using `repeat()` Lit
13
+ * directive is better for performance as that directive can track when items
14
+ * change order.
15
+ *
16
+ * Without repeat, calling `keyed()` inside of `.map()` is going to be quite
17
+ * expensive when a single item is added to the top - that will destroy each
18
+ * element below it and re-create it.
19
+ *
20
+ * When key wasn't provided, we assume that the order of items is static or that
21
+ * modifying the item dom node is cheaper than getting the key and reordering.
22
+ *
23
+ * We could have the Stencil to Lit codemod do the `.map()` to `repeat()`
24
+ * conversion in cases when the map was given an arrow function with a JSX
25
+ * element with a key, however, some issues with that:
26
+ *
27
+ * - For people coming from Stencil or React, it would be confusing to see
28
+ * `repeat()` in the code rather than the familiar `.map()`.
29
+ * - People may not know when to use which, or forget and use `.map()` with a
30
+ * `key` inside.
31
+ * - Since many JSX frameworks handle `key` inside a `.map()` correctly, if in
32
+ * the future we move from Lit, it would be nice to have the `key` prop
33
+ * already in the source code.
34
+ *
35
+ * Thus, instead of doing the conversion in the codemod, I am doing it at build
36
+ * time in the _JSX to lit-html_ transformer.
37
+ *
38
+ * If we were to do this in the codemod, the same code would have to be written
39
+ * anyway, but here we get ongoing benefit of having code always using the
40
+ * correct, performant pattern.
41
+ *
42
+ * We are only replacing `.map()` with `repeat()` if the map JSX element has a
43
+ * key prop. There may be some more complex patterns where key was used that we
44
+ * can't yet detect - those may have worse performance, but the developer can
45
+ * always call `repeat()` manually.
46
+ *
47
+ * @see https://github.com/lit/lit.dev/issues/1351
48
+ */
49
+ export declare function maybeInsertRepeatCall(context: JsxContext, node: ts.CallExpression): ts.CallExpression;
@@ -0,0 +1,11 @@
1
+ import ts from "typescript";
2
+ import type { TemplatePart } from "./templateParts";
3
+ import type { JsxHost } from "./types";
4
+ import { type JsxContext } from "./types";
5
+ /**
6
+ * Recursively traverse the entire AST top-down, converting JSX to lit-html.
7
+ */
8
+ export declare function jsxVisitor<Type extends ts.Node = ts.Node>(context: JsxContext, node: Type): Type;
9
+ export declare function jsxHostToLitExpression(context: JsxContext, jsxHost: JsxHost): ts.Expression;
10
+ export declare const findKeyPropertyIndex: (jsxElement: ts.JsxOpeningElement | ts.JsxSelfClosingElement) => number;
11
+ export declare function jsxExpressionToTemplateParts(context: JsxContext, jsxExpression: ts.JsxExpression): [] | [TemplatePart];
@@ -0,0 +1,17 @@
1
+ import ts from "typescript";
2
+ import { type JsxContext, type LitTag } from "./types";
3
+ /**
4
+ * Template part is a convenient intermediate representation for template
5
+ * literal expressions.
6
+ *
7
+ * String template literal parts will be joined together, and expressions will
8
+ * be put inside of `${}`.
9
+ */
10
+ export type TemplatePart = ts.Expression | string;
11
+ export type JsxHostTemplateParts = {
12
+ readonly key: ts.Expression | undefined;
13
+ readonly parts: TemplatePart[];
14
+ readonly litTag: LitTag | undefined;
15
+ };
16
+ export declare const isNonEmptyTemplatePart: (part: TemplatePart) => boolean;
17
+ export declare function templatePartsToLitExpression({ key, parts, litTag }: JsxHostTemplateParts, context: JsxContext): ts.Expression;
@@ -0,0 +1,10 @@
1
+ import type { JsxContext } from "./types";
2
+ /**
3
+ * Throw if encountered an explicit non-type-only import for a Calcite component
4
+ * or some `@arcgis/*` component package - such packages should be externalized,
5
+ * so there should not be explicit imports from them (otherwise, they would get
6
+ * bundled in)
7
+ *
8
+ * If there are exceptions to this rule, please notify Lumina maintainers.
9
+ */
10
+ export declare function throwOnImportingExternalized(context: JsxContext): [];
@@ -0,0 +1,80 @@
1
+ import ts from "typescript";
2
+ import type { ResolvedDependencyComponents } from "../dependencies/discover";
3
+ import type { CompilerContext } from "../context";
4
+ export type JsxContext = {
5
+ readonly compiler: CompilerContext;
6
+ /** Source file before the _JSX to lit-html_ transformation */
7
+ readonly sourceFile: ts.SourceFile;
8
+ readonly transformationContext: ts.TransformationContext;
9
+ /**
10
+ * All encountered native HTML elements and custom-elements along with a
11
+ * reference to a TypeScript JSX node where first occurrence was. You can use
12
+ * the TypeScript node to find the location where component was declared and
13
+ * thus inform what import paths need to be added in the current file.
14
+ *
15
+ * If you successfully resolved some element from this map, then please
16
+ * remove it from the map to not confuse any following resolvers.
17
+ */
18
+ readonly customElementsToImport: Set<string>;
19
+ /**
20
+ * Existing imported modules.
21
+ *
22
+ * If original specifier was for an external package, this will include the
23
+ * specifier as is.
24
+ *
25
+ * If original specifier was to a relative file, the path will be resolved
26
+ * to an absolute path, but without a file extension.
27
+ *
28
+ * Can be used to inform what custom elements are already imported
29
+ */
30
+ readonly existingImportedModules: Set<string>;
31
+ /**
32
+ * A set of absolute paths to modules in the current package from which the
33
+ * current file imported capitalized identifiers (capitalized identifier is
34
+ * often a functional component, though not always)
35
+ */
36
+ readonly importedFunctionComponentsFromModules: Set<string>;
37
+ readonly existingLitImports: Set<JsxImportName>;
38
+ readonly neededImports: Set<JsxImportName>;
39
+ readonly externalComponents: ResolvedDependencyComponents["components"];
40
+ readonly localComponents: ResolvedDependencyComponents["components"];
41
+ };
42
+ /**
43
+ * There are more lit directives, but these are the ones that can be inserted
44
+ * during the _JSX to lit-html_ conversion
45
+ */
46
+ type LitDirective = "keyed" | "ref" | "repeat";
47
+ /**
48
+ * Funny that lit called the "dynamic html" version of "html" as "staticHtml"
49
+ */
50
+ export declare const staticHtmlTag = "staticHtml";
51
+ export declare const staticSvgTag = "staticSvg";
52
+ export declare const htmlTag = "html";
53
+ export declare const svgTag = "svg";
54
+ export declare const cssTag = "css";
55
+ export declare const mathMlTag = "mathml";
56
+ declare const litTagsArray: readonly ["css", "html", "mathml", "staticHtml", "staticSvg", "svg"];
57
+ export declare const litTags: Set<"css" | "html" | "mathml" | "staticHtml" | "staticSvg" | "svg">;
58
+ export type LitTag = (typeof litTagsArray)[number];
59
+ type LuminaJsxImportName = "safeClassMap" | "safeStyleMap";
60
+ type LitMagicValue = "nothing";
61
+ export type JsxImportName = LitDirective | LitMagicValue | LitTag | LuminaJsxImportName;
62
+ export type JsxHost = ts.JsxElement | ts.JsxFragment | ts.JsxSelfClosingElement;
63
+ export declare const isJsxHost: (node: ts.Node) => node is JsxHost;
64
+ /**
65
+ * "web-types.json" has TypeScript definitions, but those are in a package that
66
+ * has a bunch of Vue dependencies, which we don't want. Opened an issue:
67
+ * https://github.com/JetBrains/web-types/issues/83
68
+ */
69
+ export type WebTypesJson = {
70
+ readonly contributions?: {
71
+ readonly html?: {
72
+ readonly elements?: readonly WebTypesElement[];
73
+ readonly tags?: readonly WebTypesElement[];
74
+ };
75
+ };
76
+ };
77
+ type WebTypesElement = {
78
+ readonly name: string;
79
+ };
80
+ export {};
@@ -0,0 +1,14 @@
1
+ export declare const jsxToLitHtmlPluginName = "@arcgis/lumina:jsxToLitHtml";
2
+ /**
3
+ * Trim whitespace in the jsx text where safe, without breaking cases like this:
4
+ * ```tsx
5
+ * <p>Format: {text}</p>
6
+ * ```
7
+ *
8
+ * This does not handle some cases if they are already handled by Prettier
9
+ * (like trailing whitespace on a line, or two consecutive non-indent white-spaces)
10
+ */
11
+ export declare function safeTrimText(text: string): string;
12
+ export declare const escapeForTemplateLiteral: (string: string) => string;
13
+ export declare const shouldQuoteAttributeValue: (value: string) => boolean;
14
+ export declare const escapeForHtml: (string: string) => string;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ import type { Plugin } from "@custom-elements-manifest/analyzer";
2
+ import type { ClassMember } from "custom-elements-manifest";
3
+ import type { CompilerContext } from "../../context";
4
+ export declare function addComponentMetadata(context: CompilerContext): Plugin;
5
+ export declare const isPublic: (member: ClassMember) => boolean;
@@ -0,0 +1,6 @@
1
+ import type { Plugin } from "@custom-elements-manifest/analyzer";
2
+ import type { CompilerContext } from "../../context";
3
+ /**
4
+ * Extract extra metadata about methods to match what Stencil's docs.json contains
5
+ */
6
+ export declare function addMethodMetadata(context: CompilerContext): Plugin;
@@ -0,0 +1,8 @@
1
+ import type { Plugin } from "@custom-elements-manifest/analyzer";
2
+ import type { ExtendedManifestEvent } from "./types";
3
+ import type { CompilerContext } from "../../context";
4
+ export type PropMetadataContext = (Pick<ExtendedManifestEvent, "bubbles" | "cancelable" | "composed"> & {
5
+ eventName: string;
6
+ })[];
7
+ /** Resolve complex types and their references */
8
+ export declare function addPropMetadata(context: CompilerContext): Plugin;
@@ -0,0 +1,18 @@
1
+ import type { ExtendedManifestField } from "./types";
2
+ import ts from "typescript";
3
+ export declare function symbolToDocs(checker: ts.TypeChecker, symbol: ts.Signature | ts.Symbol): Pick<ExtendedManifestField, "description" | "docsTags">;
4
+ export declare const notPublicJsDocTag = "notPublic";
5
+ export declare const internalJsDocTag = "internal";
6
+ export declare const findDecorator: ({ modifiers }: {
7
+ modifiers?: readonly ts.ModifierLike[];
8
+ }, name: string) => ts.CallExpression | undefined;
9
+ /**
10
+ * More strict than CEM's default:
11
+ * https://github.com/open-wc/custom-elements-manifest/blob/94650b64f992c216ff770ac9e398db7c4491c949/packages/analyzer/src/features/analyse-phase/creators/handlers.js#L289-L294
12
+ */
13
+ export declare const isDefaultValueDocumentationEligible: (initializer: ts.Expression | undefined) => initializer is ts.Expression;
14
+ /**
15
+ * Remove null and undefined from resolved type string to keep the docs cleaner.
16
+ * All non-required properties could be null or undefined.
17
+ */
18
+ export declare function stripNullables(type: string): string;
@@ -0,0 +1,9 @@
1
+ import ts from "typescript";
2
+ import type { ComponentCompilerEventType } from "./types";
3
+ import type { ContextDirectories } from "../../context/types";
4
+ /**
5
+ * If property is an event emitter, extract event payload type and event name.
6
+ * Even name is derived by converting property name to kebab-case.
7
+ */
8
+ export declare function extractEventType(checker: ts.TypeChecker, propertyDeclaration: ts.PropertyDeclaration, resolvedType: ts.Type, sourceFile: ts.SourceFile, dirs: ContextDirectories): ComponentCompilerEventType | undefined;
9
+ export declare function extractBoolean(objectLiteral: ts.ObjectLiteralExpression, name: string): boolean | undefined;
@@ -0,0 +1,11 @@
1
+ import ts from "typescript";
2
+ import type { ComponentCompilerEventType, ComponentCompilerPropertyComplexType } from "./types";
3
+ import type { JsonDocsValue } from "@stencil/core/internal";
4
+ import type { ContextDirectories } from "../../context/types";
5
+ /**
6
+ * @remarks
7
+ * Based on Stencil's getComplexType function:
8
+ * https://github.com/ionic-team/stencil/blob/b40ebb937869aa16f9adc672129639167406cd07/src/compiler/transformers/decorators-to-static/prop-decorator.ts#L165
9
+ */
10
+ export declare const getComplexPropertyType: (checker: ts.TypeChecker, dirs: ContextDirectories, decoratedNode: ts.AccessorDeclaration | ts.PropertyDeclaration, typeContainerNode: ts.AccessorDeclaration | ts.PropertyDeclaration) => ComponentCompilerEventType | ComponentCompilerPropertyComplexType | undefined;
11
+ export declare const hasLiteralTypeValue: (typeValues: JsonDocsValue[]) => boolean;