@stencil/core 5.0.0-rc.0 → 5.0.0-rc.10

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.
@@ -1,9 +1,9 @@
1
1
  import { n as __require } from "./rolldown-runtime-BhDjJH2R.mjs";
2
- import { A as SSR_PROP_REF_PREFIX, D as HYDRATE_ID, E as HYDRATE_CHILD_ID, O as SERVER_BUILD_FLAGS, T as HYDRATED_CSS, k as SSR_PROPS_REGISTRY_KEY, w as CLIENT_BUILD_FLAGS } from "./client-ClM4H9-P.mjs";
3
- import { $ as VALID_CONFIG_OUTPUT_TARGETS, A as DIST_LAZY, D as COPY, E as COLLECTION_MANIFEST_FILE_NAME, J as STANDALONE, L as EVENT_FLAGS, P as DOCS_JSON, Q as TYPES, R as GENERATED_DTS, S as ASSETS, T as COLLECTION_APP_DATA_FILE_NAME, U as LOADER_BUNDLE, X as STYLE_EXT, Y as STATS, a as isBoolean$1, b as unique, c as isFunction, d as isObject, et as WATCH_FLAGS, f as isString$1, g as sortBy, i as fromEntries, l as isIterable, m as noop, p as mergeIntoWith, r as flatOne, t as dashToPascalCase, u as isNumber$1, v as toDashCase, w as COLLECTION, y as toTitleCase, z as GLOBAL_STYLE } from "./helpers-Cpp3qc3u.mjs";
4
- import { C as isRootPath, D as byteSize, E as stringifyRuntimeData, O as escapeRegExpSpecialCharacters, S as splitLineBreaks, _ as createOnWarnFn, a as getRolldownSourceMapOptions, c as relativizeSourceMap, d as map, f as ok, g as loadTypeScriptDiagnostics, h as loadTypeScriptDiagnostic, i as getInlineSourceMappingUrlLinker, l as rolldownToStencilSourceMap, m as augmentDiagnosticWithNode, n as validateComponentTag, o as getSourceMappingUrlForEndOfFile, r as isRemoteUrl, t as validateComponentModes, u as err, v as isRolldownError, w as formatComponentRuntimeMeta, x as normalizeDiagnostics, y as loadRolldownDiagnostics } from "./validation-ByYYKvnS.mjs";
5
- import { $ as buildWarn, A as isOutputTargetDocsVscode, B as isValidConfigOutputTarget, C as isOutputTargetDistLazy, D as isOutputTargetDocsCustomElementsManifest, E as isOutputTargetDocsCustom, F as isOutputTargetSsrWasm, G as normalizeFsPath, H as shouldExcludeComponent, I as isOutputTargetStandalone, J as relative$1, K as normalizeFsPathQuery, L as isOutputTargetStats, M as isOutputTargetLoaderBundle, N as isOutputTargetServerRenderer, O as isOutputTargetDocsJson, P as isOutputTargetSsr, Q as buildJsonFileError, R as isOutputTargetTypes, S as isOutputTargetCustom, T as isOutputTargetDocsAgentSkill, U as join$2, V as relativeImport, Y as resolve$2, Z as buildError, a as hasDependency, b as isOutputTargetCollection, d as parsePackageJson, et as catchError, f as readOnlyArrayHasStringMember, g as getComponentsDtsSrcFilePath, h as filterExcludedComponents, i as getTextDocs, it as isGlob, j as isOutputTargetGlobalStyle, k as isOutputTargetDocsReadme, l as isTsFile, m as filterActiveTargets, n as createJsVarName, nt as hasWarning, o as isDtsFile, p as readPackageJson, q as normalizePath, r as generatePreamble, t as addDocBlock, tt as hasError, u as isTsxFile, v as getComponentsFromModules, w as isOutputTargetDocs, x as isOutputTargetCopy, y as isOutputTargetAssets, z as isOutputTargetWww } from "./util-C-H1H84W.mjs";
6
- import { i as CustomElementsExportBehaviorOptions, o as buildEvents, r as createNodeLogger, t as createNodeSys } from "./node-DJP8JuAS.mjs";
2
+ import { A as SSR_PROP_REF_PREFIX, D as HYDRATE_ID, E as HYDRATE_CHILD_ID, O as SERVER_BUILD_FLAGS, T as HYDRATED_CSS, k as SSR_PROPS_REGISTRY_KEY, w as CLIENT_BUILD_FLAGS } from "./client-DkvdNuPu.mjs";
3
+ import { $ as VALID_CONFIG_OUTPUT_TARGETS, A as DIST_LAZY, D as COPY, E as COLLECTION_MANIFEST_FILE_NAME, J as STANDALONE, L as EVENT_FLAGS, P as DOCS_JSON, Q as TYPES, R as GENERATED_DTS, S as ASSETS, T as COLLECTION_APP_DATA_FILE_NAME, U as LOADER_BUNDLE, X as STYLE_EXT, Y as STATS, a as isBoolean$1, b as unique, c as isFunction, d as isObject, et as WATCH_FLAGS, f as isString$1, g as sortBy, i as fromEntries, l as isIterable, m as noop, p as mergeIntoWith, r as flatOne, t as dashToPascalCase, u as isNumber$1, v as toDashCase, w as COLLECTION, y as toTitleCase, z as GLOBAL_STYLE } from "./helpers-pTCZhNi0.mjs";
4
+ import { C as isRootPath, D as byteSize, E as stringifyRuntimeData, O as escapeRegExpSpecialCharacters, S as splitLineBreaks, _ as createOnWarnFn, a as getRolldownSourceMapOptions, c as relativizeSourceMap, d as map, f as ok, g as loadTypeScriptDiagnostics, h as loadTypeScriptDiagnostic, i as getInlineSourceMappingUrlLinker, l as rolldownToStencilSourceMap, m as augmentDiagnosticWithNode, n as validateComponentTag, o as getSourceMappingUrlForEndOfFile, r as isRemoteUrl, t as validateComponentModes, u as err, v as isRolldownError, w as formatComponentRuntimeMeta, x as normalizeDiagnostics, y as loadRolldownDiagnostics } from "./validation-C1mr0klL.mjs";
5
+ import { $ as buildWarn, A as isOutputTargetDocsVscode, B as isValidConfigOutputTarget, C as isOutputTargetDistLazy, D as isOutputTargetDocsCustomElementsManifest, E as isOutputTargetDocsCustom, F as isOutputTargetSsrWasm, G as normalizeFsPath, H as shouldExcludeComponent, I as isOutputTargetStandalone, J as relative$1, K as normalizeFsPathQuery, L as isOutputTargetStats, M as isOutputTargetLoaderBundle, N as isOutputTargetServerRenderer, O as isOutputTargetDocsJson, P as isOutputTargetSsr, Q as buildJsonFileError, R as isOutputTargetTypes, S as isOutputTargetCustom, T as isOutputTargetDocsAgentSkill, U as join$2, V as relativeImport, Y as resolve$2, Z as buildError, a as hasDependency, b as isOutputTargetCollection, d as parsePackageJson, et as catchError, f as readOnlyArrayHasStringMember, g as getComponentsDtsSrcFilePath, h as filterExcludedComponents, i as getTextDocs, it as isGlob, j as isOutputTargetGlobalStyle, k as isOutputTargetDocsReadme, l as isTsFile, m as filterActiveTargets, n as createJsVarName, nt as hasWarning, o as isDtsFile, p as readPackageJson, q as normalizePath, r as generatePreamble, t as addDocBlock, tt as hasError, u as isTsxFile, v as getComponentsFromModules, w as isOutputTargetDocs, x as isOutputTargetCopy, y as isOutputTargetAssets, z as isOutputTargetWww } from "./util-CP6-333M.mjs";
6
+ import { i as CustomElementsExportBehaviorOptions, o as buildEvents, r as createNodeLogger, t as createNodeSys } from "./node-C59vQZNg.mjs";
7
7
  import ts, { default as ts$1 } from "typescript";
8
8
  import { readFileSync } from "node:fs";
9
9
  import { basename, dirname, isAbsolute, join, resolve } from "node:path";
@@ -461,9 +461,9 @@ const scopeCss = (cssText, scopeId, commentOriginalSelector) => {
461
461
  };
462
462
  //#endregion
463
463
  //#region src/version.ts
464
- const version = "5.0.0-rc.0";
465
- const buildId = "1794483140";
466
- const vermoji = "🏙";
464
+ const version = "5.0.0-rc.10";
465
+ const buildId = "1795615384";
466
+ const vermoji = "🚅";
467
467
  /**
468
468
  * Get the installed version of a tool/dependency.
469
469
  * Handles packages with exports maps that point to subdirectories.
@@ -1527,6 +1527,33 @@ const propertyToStyleDoc = (prop) => ({
1527
1527
  */
1528
1528
  const isJsDocComment = (commentText) => commentText.startsWith("*") || commentText.startsWith("!");
1529
1529
  /**
1530
+ * An explicit `@prop` annotation tag in a CSS docstring. `@cssprop`/`@cssproperty` are also
1531
+ * recognized as synonyms (the more common names in other web-component-analyzer/docgen
1532
+ * ecosystems).
1533
+ */
1534
+ const CSS_PROP_ANNOTATION_RE = /@(?:cssproperty|cssprop|prop)\b/;
1535
+ /**
1536
+ * An annotation tag that documents something by name (`@prop --x`, `@slot name`, ...) rather
1537
+ * than describing the node below its comment.
1538
+ */
1539
+ const CSS_ANNOTATION_TAG_RE = /@(?:component|cssproperty|cssprop|prop|attr|slot)\b/;
1540
+ const INTERNAL_TAG_RE = /@internal\b/;
1541
+ /**
1542
+ * Whether a comment marks the node immediately following it as internal - excluded from docs,
1543
+ * matching `@internal` on component members.
1544
+ * @param commentText a postcss `Comment` node's `.text`
1545
+ * @returns `true` if the comment is a JSDoc-style comment holding an `@internal` tag
1546
+ */
1547
+ const isInternalDocComment = (commentText) => isJsDocComment(commentText) && INTERNAL_TAG_RE.test(commentText);
1548
+ /**
1549
+ * Whether a comment describes the node immediately following it (a declaration, rule or
1550
+ * at-rule). A comment holding annotation tags documents the things it names instead, and an
1551
+ * `@internal` comment hides the node.
1552
+ * @param commentText a postcss `Comment` node's `.text`
1553
+ * @returns `true` if the comment is a JSDoc-style description of the next node
1554
+ */
1555
+ const isNodeDocComment = (commentText) => isJsDocComment(commentText) && !CSS_ANNOTATION_TAG_RE.test(commentText) && !INTERNAL_TAG_RE.test(commentText);
1556
+ /**
1530
1557
  * Strip the leading `*`/`!` marker and per-line `*` prefixes, returning trimmed lines.
1531
1558
  * @param commentText a postcss `Comment` node's `.text`
1532
1559
  * @returns the comment's lines, delimiters and leading `*`s stripped
@@ -1690,7 +1717,10 @@ const parseCssComponentFile = async (filePath, cssText) => {
1690
1717
  }
1691
1718
  }
1692
1719
  collectAttributeRuleDocs(rawRoot, (selector) => defs.get(selector.tag ?? ""), attributeRuleDocs);
1693
- for (const [def, docsByName] of attributeRuleDocs) for (const attr of def.attributes) if (attr.source === "auto") attr.docs = docsByName.get(attr.name) ?? attr.docs;
1720
+ for (const [def, docsByName] of attributeRuleDocs) {
1721
+ def.attributes = def.attributes.filter((attr) => attr.source !== "auto" || docsByName.get(attr.name) !== null);
1722
+ for (const attr of def.attributes) if (attr.source === "auto") attr.docs = docsByName.get(attr.name) ?? attr.docs;
1723
+ }
1694
1724
  for (const node of nodes) {
1695
1725
  if (node.type !== "rule") continue;
1696
1726
  for (const selector of parseSelectorList(node.selector)) {
@@ -1704,9 +1734,10 @@ const parseCssComponentFile = async (filePath, cssText) => {
1704
1734
  if (node.type !== "atrule" || node.name !== "property") continue;
1705
1735
  const propName = node.params.trim();
1706
1736
  if (!propName.startsWith("--")) continue;
1707
- const { syntax, initialValue } = parsePropertyAtRuleDescriptors(node);
1708
1737
  const prev = nodes[i - 1];
1709
- const docs = prev && prev.type === "comment" && isJsDocComment(prev.text) ? normalizeJsDocText(prev.text) : "";
1738
+ const isInternal = prev?.type === "comment" && isInternalDocComment(prev.text);
1739
+ const { syntax, initialValue } = parsePropertyAtRuleDescriptors(node);
1740
+ const docs = prev && prev.type === "comment" && isNodeDocComment(prev.text) ? normalizeJsDocText(prev.text) : "";
1710
1741
  for (const def of defs.values()) {
1711
1742
  const existing = def.properties.find((p) => p.name === propName);
1712
1743
  if (existing) {
@@ -1715,6 +1746,7 @@ const parseCssComponentFile = async (filePath, cssText) => {
1715
1746
  if (initialValue) existing.default ??= initialValue;
1716
1747
  continue;
1717
1748
  }
1749
+ if (isInternal) continue;
1718
1750
  const prop = {
1719
1751
  name: propName,
1720
1752
  docs,
@@ -1738,6 +1770,7 @@ const parseCssComponentFile = async (filePath, cssText) => {
1738
1770
  * @param def the CSS-only component definition the found slots belong to
1739
1771
  */
1740
1772
  const collectAutoDetectedSlots = (container, def) => {
1773
+ const internal = /* @__PURE__ */ new Set();
1741
1774
  for (const nested of container.nodes) {
1742
1775
  if (nested.type !== "rule") continue;
1743
1776
  const names = /* @__PURE__ */ new Set();
@@ -1748,10 +1781,15 @@ const collectAutoDetectedSlots = (container, def) => {
1748
1781
  } catch {
1749
1782
  continue;
1750
1783
  }
1784
+ const prev = nested.prev();
1785
+ const isInternal = prev?.type === "comment" && isInternalDocComment(prev.text);
1751
1786
  for (const name of names) {
1752
- if (def.slots.some((s) => s.name === name)) continue;
1753
- const prev = nested.prev();
1754
- const docs = prev && prev.type === "comment" && isJsDocComment(prev.text) ? normalizeJsDocText(prev.text) : "";
1787
+ if (internal.has(name) || def.slots.some((s) => s.name === name)) continue;
1788
+ if (isInternal) {
1789
+ internal.add(name);
1790
+ continue;
1791
+ }
1792
+ const docs = prev && prev.type === "comment" && isNodeDocComment(prev.text) ? normalizeJsDocText(prev.text) : "";
1755
1793
  def.slots.push({
1756
1794
  name,
1757
1795
  docs,
@@ -1848,8 +1886,8 @@ const collectAutoDetectedAttributes = (selector, def) => {
1848
1886
  };
1849
1887
  /**
1850
1888
  * Record the JSDoc comment directly above each of `container`'s child rules as the description
1851
- * of the attributes in that rule's leading compound selector. The first documented rule for an
1852
- * attribute wins.
1889
+ * of the attributes in that rule's leading compound selector, or `null` for an `@internal`
1890
+ * comment. The first documented rule for an attribute wins.
1853
1891
  * @param container a container whose direct child rules to scan
1854
1892
  * @param defFor the component a child rule's selector belongs to, if any
1855
1893
  * @param out collected descriptions, per component, by attribute name
@@ -1857,14 +1895,16 @@ const collectAutoDetectedAttributes = (selector, def) => {
1857
1895
  const collectAttributeRuleDocs = (container, defFor, out) => {
1858
1896
  for (const node of container.nodes) {
1859
1897
  const prev = node.prev();
1860
- if (node.type !== "rule" || prev?.type !== "comment" || !isJsDocComment(prev.text)) continue;
1898
+ if (node.type !== "rule" || prev?.type !== "comment") continue;
1899
+ const isInternal = isInternalDocComment(prev.text);
1900
+ if (!isInternal && !isNodeDocComment(prev.text)) continue;
1861
1901
  let selectors;
1862
1902
  try {
1863
1903
  selectors = parseSelectorList(node.selector);
1864
1904
  } catch {
1865
1905
  continue;
1866
1906
  }
1867
- const docs = normalizeJsDocText(prev.text);
1907
+ const docs = isInternal ? null : normalizeJsDocText(prev.text);
1868
1908
  for (const selector of selectors) {
1869
1909
  const def = defFor(selector);
1870
1910
  if (!def) continue;
@@ -1887,7 +1927,7 @@ const collectAutoDetectedCustomProperties = (container, def) => {
1887
1927
  if (child.type !== "decl" || !child.prop.startsWith("--")) continue;
1888
1928
  if (def.properties.some((p) => p.name === child.prop)) continue;
1889
1929
  const prev = children[i - 1];
1890
- if (!prev || prev.type !== "comment" || !isJsDocComment(prev.text)) continue;
1930
+ if (!prev || prev.type !== "comment" || !isNodeDocComment(prev.text)) continue;
1891
1931
  def.properties.push({
1892
1932
  name: child.prop,
1893
1933
  docs: normalizeJsDocText(prev.text),
@@ -2065,28 +2105,40 @@ const scanFiles = async (config, compilerCtx, buildCtx, cache, filePaths) => {
2065
2105
  }));
2066
2106
  };
2067
2107
  /**
2068
- * Load a CSS-only component source file's text. A plain `.css` file is read as-is; any other
2069
- * `STYLE_EXT` extension is run through the configured `plugins` first (e.g. `@stencil/sass`
2070
- * compiling `.scss` to CSS) - the same pipeline `collectCssOnlyComponentStyles` uses to emit
2071
- * this file's CSS, so discovery parses exactly what gets shipped.
2108
+ * Load a CSS-only component source file's text. Only files whose raw source contains
2109
+ * `@component` are considered - a definition belongs to the file that literally contains it,
2110
+ * so preprocessor partials and importers are never compiled standalone here. A plain `.css`
2111
+ * file is returned as-is; any other `STYLE_EXT` extension is run through the configured
2112
+ * `plugins` first (e.g. `@stencil/sass` compiling `.scss` to CSS) - the same pipeline
2113
+ * `collectCssOnlyComponentStyles` uses to emit this file's CSS, so discovery parses exactly
2114
+ * what gets shipped.
2072
2115
  *
2073
2116
  * @param config the validated Stencil config
2074
2117
  * @param compilerCtx the compiler context, used to read the file and register watch files
2075
2118
  * @param buildCtx the current build context, used for plugin transform diagnostics
2076
2119
  * @param filePath absolute path to the source file to load
2077
- * @returns the (possibly preprocessed) CSS text, or `null` if the file couldn't be loaded
2120
+ * @returns the (possibly preprocessed) CSS text, or `null` if the file couldn't be loaded or
2121
+ * has no `@component` marker
2078
2122
  */
2079
2123
  const loadCssOnlyComponentSource = async (config, compilerCtx, buildCtx, filePath) => {
2080
- if (filePath.toLowerCase().endsWith(".css")) try {
2081
- return await compilerCtx.fs.readFile(filePath);
2124
+ let rawText;
2125
+ try {
2126
+ rawText = await compilerCtx.fs.readFile(filePath);
2082
2127
  } catch {
2083
2128
  return null;
2084
2129
  }
2130
+ if (!rawText.includes("@component")) return null;
2131
+ if (filePath.toLowerCase().endsWith(".css")) return rawText;
2085
2132
  const transformResults = await runPluginTransforms(config, compilerCtx, buildCtx, filePath);
2086
2133
  if (!transformResults) return null;
2087
- if (typeof transformResults === "string") return transformResults;
2088
- for (const dep of transformResults.dependencies ?? []) compilerCtx.addWatchFile(dep);
2089
- return transformResults.code ?? null;
2134
+ const code = typeof transformResults === "string" ? transformResults : transformResults.code;
2135
+ if (typeof transformResults !== "string") for (const dep of transformResults.dependencies ?? []) compilerCtx.addWatchFile(dep);
2136
+ if (code != null && !code.includes("@component")) {
2137
+ const warn = buildWarn(buildCtx.diagnostics);
2138
+ warn.messageText = `"${relative$1(config.rootDir, filePath)}" contains "@component" but its preprocessed output does not, so no CSS-only components were discovered in it. Is the preprocessor stripping comments (e.g. sass \`outputStyle: 'compressed'\`)?`;
2139
+ warn.absFilePath = filePath;
2140
+ }
2141
+ return code ?? null;
2090
2142
  };
2091
2143
  const flattenCache = (cache) => Array.from(cache.values()).flat();
2092
2144
  /**
@@ -7983,6 +8035,31 @@ const generateRolldownOutput = async (build, options, config, entryModules) => {
7983
8035
  });
7984
8036
  };
7985
8037
  //#endregion
8038
+ //#region src/compiler/output-targets/dist-lazy/cjs-import-meta-url-plugin.ts
8039
+ /**
8040
+ * With `platform: 'browser'` (shared with the ESM output), Rolldown renders `import.meta.url`
8041
+ * in CJS as `{}.url`. Replace it with the same expression Rolldown emits for `platform: 'node'`.
8042
+ */
8043
+ const EMPTY_IMPORT_META_URL = /\{\}\.url\b/g;
8044
+ const CJS_FILE_URL = `require("url").pathToFileURL(__filename).href`;
8045
+ /**
8046
+ * A Rolldown output plugin that restores `import.meta.url` in CJS chunks.
8047
+ * @param sourceMap whether to generate a source map for the replacement
8048
+ * @returns a Rolldown plugin
8049
+ */
8050
+ const cjsImportMetaUrlPlugin = (sourceMap) => ({
8051
+ name: "cjsImportMetaUrlPlugin",
8052
+ renderChunk(code) {
8053
+ if (!code.includes("{}.url")) return null;
8054
+ const s = new MagicString(code);
8055
+ s.replaceAll(EMPTY_IMPORT_META_URL, CJS_FILE_URL);
8056
+ return {
8057
+ code: s.toString(),
8058
+ map: sourceMap ? s.generateMap({ hires: true }) : null
8059
+ };
8060
+ }
8061
+ });
8062
+ //#endregion
7986
8063
  //#region src/compiler/output-targets/dist-lazy/write-lazy-entry-module.ts
7987
8064
  const writeLazyModule = async (compilerCtx, outputTargetType, destinations, code, sourceMap, rolldownResult) => {
7988
8065
  const fileName = rolldownResult.fileName;
@@ -8325,7 +8402,7 @@ const generateCjs = async (config, compilerCtx, buildCtx, rolldownBuild, outputT
8325
8402
  entryFileNames: "[name].cjs",
8326
8403
  assetFileNames: "[name]-[hash][extname]",
8327
8404
  ...getRolldownSourceMapOptions(config),
8328
- plugins: [lazyBundleIdPlugin(buildCtx, config, false, 8, ".cjs")]
8405
+ plugins: [lazyBundleIdPlugin(buildCtx, config, false, 8, ".cjs"), cjsImportMetaUrlPlugin(!!config.sourceMap)]
8329
8406
  };
8330
8407
  if (config.compat.enableImportInjection) esmOpts.dynamicImportInCjs = false;
8331
8408
  const results = await generateRolldownOutput(rolldownBuild, esmOpts, config, buildCtx.entryModules);
@@ -8333,6 +8410,7 @@ const generateCjs = async (config, compilerCtx, buildCtx, rolldownBuild, outputT
8333
8410
  const destinations = cjsOutputs.map((o) => o.cjsDir).filter((cjsDir) => typeof cjsDir === "string");
8334
8411
  buildCtx.commonJsComponentBundle = await generateLazyModules(config, compilerCtx, buildCtx, outputTargetType, destinations, results, "es2022", false);
8335
8412
  await generateShortcuts$1(compilerCtx, results, cjsOutputs);
8413
+ await writeCjsPackageJson(compilerCtx, cjsOutputs);
8336
8414
  }
8337
8415
  }
8338
8416
  return {
@@ -8340,6 +8418,14 @@ const generateCjs = async (config, compilerCtx, buildCtx, rolldownBuild, outputT
8340
8418
  buildCtx
8341
8419
  };
8342
8420
  };
8421
+ /**
8422
+ * Chunks and lazy entries in the CJS dir keep a `.js` extension, so scope them as CommonJS
8423
+ * in case the consuming package sets `"type": "module"`.
8424
+ * @param compilerCtx the current compiler context
8425
+ * @param outputTargets the output targets with a CJS dir
8426
+ * @returns a promise that resolves once each `package.json` is written
8427
+ */
8428
+ const writeCjsPackageJson = (compilerCtx, outputTargets) => Promise.all(outputTargets.map((o) => compilerCtx.fs.writeFile(join$2(o.cjsDir, "package.json"), `{"type":"commonjs"}\n`, { outputTargetType: o.type })));
8343
8429
  const generateShortcuts$1 = (compilerCtx, rolldownResult, outputTargets) => {
8344
8430
  const indexFilename = rolldownResult.find((r) => r.type === "chunk" && r.isIndex).fileName;
8345
8431
  return Promise.all(outputTargets.map(async (o) => {
@@ -8922,8 +9008,57 @@ const ProgressTask = {
8922
9008
  const AUTO_GENERATE_COMMENT = `<!-- Auto Generated Below -->`;
8923
9009
  const NOTE = `*Built with [StencilJS](https://stenciljs.com/)*`;
8924
9010
  //#endregion
9011
+ //#region src/compiler/docs/jsdoc-links.ts
9012
+ /**
9013
+ * Matches JSDoc inline link tags that reference a URL, in the
9014
+ * `[label]{@link url}`, `{@link url|label}` or `{@link url label}` form.
9015
+ */
9016
+ const JSDOC_URL_LINK_REGEX = /(?:\[([^\]]*)\])?\{@link\s+(https?:\/\/[^\s|}]+)(?:\s*[|\s]\s*([^}]*?))?\s*\}/g;
9017
+ /**
9018
+ * Converts JSDoc inline link tags that reference a URL into markdown links.
9019
+ *
9020
+ * Documentation output targets (docs-readme, docs-json, docs-vscode) treat their
9021
+ * `docs` fields as markdown, so URL-based `{@link}` tags are converted so they
9022
+ * render as links.
9023
+ *
9024
+ * Symbol links like `{@link MyClass#foo}` are left untouched, since resolving them
9025
+ * to a URL would require type information the docs generators do not have.
9026
+ *
9027
+ * @param text the JSDoc text to convert
9028
+ * @returns the text with URL-based `{@link}` tags converted to markdown links
9029
+ */
9030
+ const convertJsdocLinksToMarkdown = (text) => {
9031
+ if (!text || !text.includes("{@link")) return text;
9032
+ return text.replace(JSDOC_URL_LINK_REGEX, (_match, prefixLabel, url, label) => {
9033
+ return `[${prefixLabel?.trim() || label?.trim() || url}](${url})`;
9034
+ });
9035
+ };
9036
+ /**
9037
+ * Converts URL-based `{@link}` tags in the text of JSDoc tag infos (e.g. the texts
9038
+ * behind `@deprecated` or `@returns`) into markdown links, so tag-derived docs
9039
+ * fields render as links too.
9040
+ * @param tags the JSDoc tag infos to convert
9041
+ * @returns new tag infos with URL-based `{@link}` tags converted to markdown links
9042
+ */
9043
+ const convertJsdocTagsToMarkdown = (tags) => {
9044
+ return tags.map((tag) => ({
9045
+ ...tag,
9046
+ text: convertJsdocLinksToMarkdown(tag.text)
9047
+ }));
9048
+ };
9049
+ //#endregion
8925
9050
  //#region src/compiler/docs/generate-doc-data.ts
8926
9051
  /**
9052
+ * Converts the text and tag texts of a component's JSDoc into markdown, so every
9053
+ * docs field derived from it renders URL-based `{@link}` tags as markdown links.
9054
+ * @param jsdoc the JSDoc to convert
9055
+ * @returns the converted JSDoc
9056
+ */
9057
+ const convertCompilerJsDoc = (jsdoc) => ({
9058
+ text: convertJsdocLinksToMarkdown(jsdoc.text),
9059
+ tags: convertJsdocTagsToMarkdown(jsdoc.tags)
9060
+ });
9061
+ /**
8927
9062
  * Generate metadata that will be used to generate any given documentation-related
8928
9063
  * output target(s)
8929
9064
  *
@@ -8974,32 +9109,35 @@ const getDocsComponents = async (config, compilerCtx, buildCtx) => {
8974
9109
  const usagesDir = normalizePath(join$2(dirPath, "usage"));
8975
9110
  const readme = await getUserReadmeContent(compilerCtx, readmePath);
8976
9111
  const usage = await generateUsages(compilerCtx, usagesDir);
8977
- return moduleFile.cmps.filter((cmp) => !cmp.internal && !cmp.isCollectionDependency).map((cmp) => ({
8978
- dirPath,
8979
- filePath: normalizePath(relative$1(config.rootDir, filePath), false),
8980
- fileName: basename$1(filePath),
8981
- readmePath,
8982
- usagesDir,
8983
- tag: cmp.tagName,
8984
- readme,
8985
- overview: cmp.docs.text,
8986
- usage,
8987
- docs: generateDocs(readme, cmp.docs),
8988
- docsTags: cmp.docs.tags,
8989
- encapsulation: getDocsEncapsulation(cmp),
8990
- dependents: cmp.directDependents,
8991
- dependencies: cmp.directDependencies,
8992
- dependencyGraph: buildDocsDepGraph(cmp, buildCtx.components),
8993
- deprecation: getDocsDeprecationText(cmp.docs.tags),
8994
- props: getDocsProperties(cmp),
8995
- methods: getDocsMethods(cmp.methods),
8996
- events: getDocsEvents(cmp.events),
8997
- styles: getDocsStyles(cmp),
8998
- slots: getDocsSlots(cmp.htmlSlots, cmp.docs.tags),
8999
- parts: getDocsParts(cmp.htmlParts, cmp.docs.tags),
9000
- customStates: getDocsCustomStates(cmp),
9001
- listeners: getDocsListeners(cmp.listeners)
9002
- }));
9112
+ return moduleFile.cmps.filter((cmp) => !cmp.internal && !cmp.isCollectionDependency).map((cmp) => {
9113
+ const docs = convertCompilerJsDoc(cmp.docs);
9114
+ return {
9115
+ dirPath,
9116
+ filePath: normalizePath(relative$1(config.rootDir, filePath), false),
9117
+ fileName: basename$1(filePath),
9118
+ readmePath,
9119
+ usagesDir,
9120
+ tag: cmp.tagName,
9121
+ readme,
9122
+ overview: docs.text,
9123
+ usage,
9124
+ docs: generateDocs(readme, docs),
9125
+ docsTags: docs.tags,
9126
+ encapsulation: getDocsEncapsulation(cmp),
9127
+ dependents: cmp.directDependents,
9128
+ dependencies: cmp.directDependencies,
9129
+ dependencyGraph: buildDocsDepGraph(cmp, buildCtx.components),
9130
+ deprecation: getDocsDeprecationText(docs.tags),
9131
+ props: getDocsProperties(cmp),
9132
+ methods: getDocsMethods(cmp.methods),
9133
+ events: getDocsEvents(cmp.events),
9134
+ styles: getDocsStyles(cmp),
9135
+ slots: getDocsSlots(cmp.htmlSlots, docs.tags),
9136
+ parts: getDocsParts(cmp.htmlParts, docs.tags),
9137
+ customStates: getDocsCustomStates(cmp),
9138
+ listeners: getDocsListeners(cmp.listeners)
9139
+ };
9140
+ });
9003
9141
  }));
9004
9142
  return sortBy(flatOne(results), (cmp) => cmp.tag);
9005
9143
  };
@@ -9017,6 +9155,7 @@ const getCssOnlyDocsComponents = async (config, compilerCtx, buildCtx) => {
9017
9155
  const usagesDir = normalizePath(join$2(dirPath, "usage"));
9018
9156
  const readme = await getUserReadmeContent(compilerCtx, readmePath);
9019
9157
  const usage = await generateUsages(compilerCtx, usagesDir);
9158
+ const docs = convertCompilerJsDoc(cmp.docs);
9020
9159
  return {
9021
9160
  dirPath,
9022
9161
  filePath: normalizePath(relative$1(config.rootDir, filePath), false),
@@ -9025,21 +9164,21 @@ const getCssOnlyDocsComponents = async (config, compilerCtx, buildCtx) => {
9025
9164
  usagesDir,
9026
9165
  tag: cmp.tagName,
9027
9166
  readme,
9028
- overview: cmp.docs.text,
9167
+ overview: docs.text,
9029
9168
  usage,
9030
- docs: generateDocs(readme, cmp.docs),
9031
- docsTags: cmp.docs.tags,
9169
+ docs: generateDocs(readme, docs),
9170
+ docsTags: docs.tags,
9032
9171
  encapsulation: getDocsEncapsulation(cmp),
9033
9172
  dependents: cmp.directDependents,
9034
9173
  dependencies: cmp.directDependencies,
9035
9174
  dependencyGraph: buildDocsDepGraph(cmp, buildCtx.components),
9036
- deprecation: getDocsDeprecationText(cmp.docs.tags),
9175
+ deprecation: getDocsDeprecationText(docs.tags),
9037
9176
  props: getDocsProperties(cmp),
9038
9177
  methods: getDocsMethods(cmp.methods),
9039
9178
  events: getDocsEvents(cmp.events),
9040
9179
  styles: getDocsStyles(cmp),
9041
- slots: getDocsSlots(cmp.htmlSlots, cmp.docs.tags),
9042
- parts: getDocsParts(cmp.htmlParts, cmp.docs.tags),
9180
+ slots: getDocsSlots(cmp.htmlSlots, docs.tags),
9181
+ parts: getDocsParts(cmp.htmlParts, docs.tags),
9043
9182
  customStates: getDocsCustomStates(cmp),
9044
9183
  listeners: getDocsListeners(cmp.listeners),
9045
9184
  cssOnly: true
@@ -9089,23 +9228,26 @@ const getDocsProperties = (cmpMeta) => {
9089
9228
  * @returns the derived metadata
9090
9229
  */
9091
9230
  const getRealProperties = (properties) => {
9092
- return properties.filter((member) => !member.internal).map((member) => ({
9093
- name: member.name,
9094
- type: member.complexType.resolved,
9095
- complexType: member.complexType,
9096
- mutable: member.mutable,
9097
- attr: member.attribute,
9098
- reflectToAttr: !!member.reflect,
9099
- docs: member.docs.text,
9100
- docsTags: member.docs.tags,
9101
- default: member.defaultValue,
9102
- deprecation: getDocsDeprecationText(member.docs.tags),
9103
- values: parseTypeIntoValues(member.complexType.resolved),
9104
- optional: member.optional,
9105
- required: member.required,
9106
- getter: member.getter,
9107
- setter: member.setter
9108
- }));
9231
+ return properties.filter((member) => !member.internal).map((member) => {
9232
+ const docs = convertCompilerJsDoc(member.docs);
9233
+ return {
9234
+ name: member.name,
9235
+ type: member.complexType.resolved,
9236
+ complexType: member.complexType,
9237
+ mutable: member.mutable,
9238
+ attr: member.attribute,
9239
+ reflectToAttr: !!member.reflect,
9240
+ docs: docs.text,
9241
+ docsTags: docs.tags,
9242
+ default: member.defaultValue,
9243
+ deprecation: getDocsDeprecationText(docs.tags),
9244
+ values: parseTypeIntoValues(member.complexType.resolved),
9245
+ optional: member.optional,
9246
+ required: member.required,
9247
+ getter: member.getter,
9248
+ setter: member.setter
9249
+ };
9250
+ });
9109
9251
  };
9110
9252
  /**
9111
9253
  * Generate a collection of JSDoc metadata for props on a component
@@ -9119,7 +9261,7 @@ const getVirtualProperties = (virtualProps) => {
9119
9261
  mutable: false,
9120
9262
  attr: member.name,
9121
9263
  reflectToAttr: false,
9122
- docs: member.docs,
9264
+ docs: convertJsdocLinksToMarkdown(member.docs),
9123
9265
  docsTags: [],
9124
9266
  default: void 0,
9125
9267
  deprecation: void 0,
@@ -9170,32 +9312,38 @@ const parseTypeIntoValues = (type) => {
9170
9312
  return [];
9171
9313
  };
9172
9314
  const getDocsMethods = (methods) => {
9173
- return sortBy(methods, (member) => member.name).filter((member) => !member.internal).map((member) => ({
9174
- name: member.name,
9175
- returns: {
9176
- type: member.complexType.return,
9177
- docs: member.docs.tags.filter((t) => t.name === "return" || t.name === "returns").map((t) => t.text).join("\n")
9178
- },
9179
- complexType: member.complexType,
9180
- signature: `${member.name}${member.complexType.signature}`,
9181
- parameters: member.complexType.parameters,
9182
- docs: member.docs.text,
9183
- docsTags: member.docs.tags,
9184
- deprecation: getDocsDeprecationText(member.docs.tags)
9185
- }));
9315
+ return sortBy(methods, (member) => member.name).filter((member) => !member.internal).map((member) => {
9316
+ const docs = convertCompilerJsDoc(member.docs);
9317
+ return {
9318
+ name: member.name,
9319
+ returns: {
9320
+ type: member.complexType.return,
9321
+ docs: docs.tags.filter((t) => t.name === "return" || t.name === "returns").map((t) => t.text).join("\n")
9322
+ },
9323
+ complexType: member.complexType,
9324
+ signature: `${member.name}${member.complexType.signature}`,
9325
+ parameters: member.complexType.parameters,
9326
+ docs: docs.text,
9327
+ docsTags: docs.tags,
9328
+ deprecation: getDocsDeprecationText(docs.tags)
9329
+ };
9330
+ });
9186
9331
  };
9187
9332
  const getDocsEvents = (events) => {
9188
- return sortBy(events, (eventMeta) => eventMeta.name.toLowerCase()).filter((eventMeta) => !eventMeta.internal).map((eventMeta) => ({
9189
- event: eventMeta.name,
9190
- detail: eventMeta.complexType.resolved,
9191
- bubbles: eventMeta.bubbles,
9192
- complexType: eventMeta.complexType,
9193
- cancelable: eventMeta.cancelable,
9194
- composed: eventMeta.composed,
9195
- docs: eventMeta.docs.text,
9196
- docsTags: eventMeta.docs.tags,
9197
- deprecation: getDocsDeprecationText(eventMeta.docs.tags)
9198
- }));
9333
+ return sortBy(events, (eventMeta) => eventMeta.name.toLowerCase()).filter((eventMeta) => !eventMeta.internal).map((eventMeta) => {
9334
+ const docs = convertCompilerJsDoc(eventMeta.docs);
9335
+ return {
9336
+ event: eventMeta.name,
9337
+ detail: eventMeta.complexType.resolved,
9338
+ bubbles: eventMeta.bubbles,
9339
+ complexType: eventMeta.complexType,
9340
+ cancelable: eventMeta.cancelable,
9341
+ composed: eventMeta.composed,
9342
+ docs: docs.text,
9343
+ docsTags: docs.tags,
9344
+ deprecation: getDocsDeprecationText(docs.tags)
9345
+ };
9346
+ });
9199
9347
  };
9200
9348
  /**
9201
9349
  * Transforms the {@link d.StyleDoc} metadata for a component into a {@link d.JsonDocsStyle}, providing sensible
@@ -9209,7 +9357,7 @@ const getDocsStyles = (cmpMeta) => {
9209
9357
  return {
9210
9358
  name: compilerStyleDoc.name,
9211
9359
  annotation: compilerStyleDoc.annotation || "",
9212
- docs: compilerStyleDoc.docs || "",
9360
+ docs: convertJsdocLinksToMarkdown(compilerStyleDoc.docs || ""),
9213
9361
  mode: compilerStyleDoc.mode && compilerStyleDoc.mode !== "$" ? compilerStyleDoc.mode : void 0,
9214
9362
  ...compilerStyleDoc.syntax && { syntax: compilerStyleDoc.syntax },
9215
9363
  ...compilerStyleDoc.default && { default: compilerStyleDoc.default }
@@ -9268,7 +9416,7 @@ const getDocsCustomStates = (cmpMeta) => {
9268
9416
  return sortBy(cmpMeta.attachInternalsCustomStates.map((state) => ({
9269
9417
  name: state.name,
9270
9418
  initialValue: state.initialValue,
9271
- docs: state.docs || ""
9419
+ docs: convertJsdocLinksToMarkdown(state.docs || "")
9272
9420
  })), (state) => state.name);
9273
9421
  };
9274
9422
  /**
@@ -9285,10 +9433,10 @@ const getDocsCustomStates = (cmpMeta) => {
9285
9433
  const cmpMetaToDocsComponent = (cmp, filePath, rootDir = process.cwd()) => {
9286
9434
  const normalizedFilePath = normalizePath(filePath);
9287
9435
  const dirPath = normalizePath(dirname$1(normalizedFilePath));
9288
- const docs = cmp.docs ?? {
9436
+ const docs = convertCompilerJsDoc(cmp.docs ?? {
9289
9437
  text: "",
9290
9438
  tags: []
9291
- };
9439
+ });
9292
9440
  return {
9293
9441
  dirPath,
9294
9442
  filePath: normalizePath(relative$1(rootDir, normalizedFilePath), false),
@@ -14401,7 +14549,7 @@ const getBundleOptions = (config, buildCtx, compilerCtx, outputTarget) => {
14401
14549
  const conditionals = getStandaloneBuildConditionals(config, buildCtx.components);
14402
14550
  mergeCollectionBuildFlags(conditionals, compilerCtx.collections);
14403
14551
  return {
14404
- id: "customElements",
14552
+ id: `customElements-${outputTarget.customElementsExportBehavior ?? "default"}`,
14405
14553
  platform: "client",
14406
14554
  conditionals,
14407
14555
  customBeforeTransformers: getCustomBeforeTransformers(config, compilerCtx, buildCtx.components, outputTarget, buildCtx),
@@ -20474,7 +20622,7 @@ const validateFilesField = async (config, compilerCtx, buildCtx) => {
20474
20622
  const packageJsonDir = dirname$1(config.packageJsonFilePath);
20475
20623
  const absPath = join$2(packageJsonDir, pkgFile);
20476
20624
  if (!await compilerCtx.fs.access(absPath)) {
20477
- const msg = `Unable to find "${pkgFile}" within the package.json "files" array.`;
20625
+ const msg = `"${pkgFile}" is listed in the package.json "files" array but could not be found on disk.`;
20478
20626
  packageJsonError(config, compilerCtx, buildCtx, msg, `"${pkgFile}"`);
20479
20627
  }
20480
20628
  }
@@ -23867,6 +24015,7 @@ const autoprefixCss = async (cssText, opts, filePath, minify = false) => {
23867
24015
  };
23868
24016
  if (typeof e.name === "string") diagnostic.header = e.name;
23869
24017
  if (typeof e.message === "string") diagnostic.messageText = e.message;
24018
+ if (e.data?.type === "SelectorError" && e.loc && typeof e.loc.line === "number") diagnostic.messageText = getSelectorErrorMessage(typeof e.source === "string" ? e.source : cssText, e.loc, diagnostic.messageText, e.data.value?.type);
23870
24019
  if (filePath) diagnostic.absFilePath = filePath;
23871
24020
  else if (typeof e.fileName === "string" && e.fileName !== "style.css") diagnostic.absFilePath = e.fileName;
23872
24021
  if (e.loc && typeof e.loc.line === "number") {
@@ -23896,6 +24045,25 @@ const autoprefixCss = async (cssText, opts, filePath, minify = false) => {
23896
24045
  return output;
23897
24046
  };
23898
24047
  /**
24048
+ * Lightning CSS selector errors (e.g. `Invalid state`) don't name the selector, and for
24049
+ * preprocessed styles the reported line is in the compiled CSS, not the source file.
24050
+ * @param sourceText the CSS that failed to parse
24051
+ * @param loc the 1-based error location reported by Lightning CSS
24052
+ * @param loc.line the error line
24053
+ * @param loc.column the error column
24054
+ * @param message the original error message
24055
+ * @param errorType the Lightning CSS selector error type
24056
+ * @returns a message that includes the offending selector
24057
+ */
24058
+ const getSelectorErrorMessage = (sourceText, loc, message, errorType) => {
24059
+ const offset = sourceText.split("\n").slice(0, loc.line - 1).reduce((acc, line) => acc + line.length + 1, 0) + (loc.column ?? 1) - 1;
24060
+ const start = Math.max(sourceText.lastIndexOf("{", offset), sourceText.lastIndexOf("}", offset), sourceText.lastIndexOf(";", offset));
24061
+ const end = sourceText.indexOf("{", offset);
24062
+ const selector = sourceText.slice(start + 1, end === -1 ? void 0 : end).trim();
24063
+ if (!selector) return message;
24064
+ return `Invalid CSS selector "${selector}": ${message}.${errorType === "InvalidState" ? ` A pseudo-class can't follow a pseudo-element (e.g. \`::before:dir(rtl)\`); move it before (\`:dir(rtl)::before\`).` : ""}`;
24065
+ };
24066
+ /**
23899
24067
  * Default browserslist targets used when autoprefixing CSS.
23900
24068
  * Targets ES2017 browsers (2022+) only.
23901
24069
  */
@@ -25344,7 +25512,7 @@ function parseScopedAndNativeStyleDocs(styleDocs, styleText, mode, tag, encapsul
25344
25512
  const child = children[i];
25345
25513
  if (child.type !== "decl" || !child.prop.startsWith("--") || hasName(child.prop)) continue;
25346
25514
  const prev = children[i - 1];
25347
- if (!prev || prev.type !== "comment" || !isJsDocComment(prev.text)) continue;
25515
+ if (!prev || prev.type !== "comment" || !isNodeDocComment(prev.text)) continue;
25348
25516
  styleDocs.push({
25349
25517
  name: child.prop,
25350
25518
  docs: normalizeJsDocText(prev.text),
@@ -25356,9 +25524,10 @@ function parseScopedAndNativeStyleDocs(styleDocs, styleText, mode, tag, encapsul
25356
25524
  root.walkAtRules("property", (node) => {
25357
25525
  const propName = node.params.trim();
25358
25526
  if (!propName.startsWith("--")) return;
25359
- const { syntax, initialValue } = parsePropertyAtRuleDescriptors(node);
25360
25527
  const prev = node.prev();
25361
- const docs = prev && prev.type === "comment" && isJsDocComment(prev.text) ? normalizeJsDocText(prev.text) : "";
25528
+ const isInternal = prev?.type === "comment" && isInternalDocComment(prev.text);
25529
+ const { syntax, initialValue } = parsePropertyAtRuleDescriptors(node);
25530
+ const docs = prev && prev.type === "comment" && isNodeDocComment(prev.text) ? normalizeJsDocText(prev.text) : "";
25362
25531
  const existing = styleDocs.find((styleDoc) => styleDoc.name === propName);
25363
25532
  if (existing) {
25364
25533
  existing.docs ||= docs;
@@ -25366,6 +25535,7 @@ function parseScopedAndNativeStyleDocs(styleDocs, styleText, mode, tag, encapsul
25366
25535
  if (initialValue) existing.default ??= initialValue;
25367
25536
  return;
25368
25537
  }
25538
+ if (isInternal) return;
25369
25539
  styleDocs.push({
25370
25540
  name: propName,
25371
25541
  docs,
@@ -25411,12 +25581,6 @@ const CSS_DOC_START = /\/\*(\*|!)/;
25411
25581
  * Closing syntax for a CSS docstring
25412
25582
  */
25413
25583
  const CSS_DOC_END = "*/";
25414
- /**
25415
- * The `@prop` annotation we support within CSS docstrings. `@cssprop`/`@cssproperty` are also
25416
- * recognized as synonyms (the more common names in other web-component-analyzer/docgen
25417
- * ecosystems).
25418
- */
25419
- const CSS_PROP_ANNOTATION_RE = /@(?:cssproperty|cssprop|prop)\b/;
25420
25584
  //#endregion
25421
25585
  //#region src/compiler/style/css-to-esm.ts
25422
25586
  /**
@@ -27100,8 +27264,27 @@ const transpileModule = (config, input, transformOpts) => {
27100
27264
  if (tsCompilerOptions.jsx != null && !isAutomaticRuntime && !isString$1(tsCompilerOptions.jsxFragmentFactory)) tsCompilerOptions.jsxFragmentFactory = "Fragment";
27101
27265
  if (tsCompilerOptions.paths && !isString$1(tsCompilerOptions.baseUrl)) tsCompilerOptions.baseUrl = ".";
27102
27266
  const sourceFile = ts.createSourceFile(sourceFilePath, input, tsCompilerOptions.target);
27103
- const program = ts.createProgram([sourceFilePath], tsCompilerOptions, {
27104
- getSourceFile: (fileName) => normalizePath(fileName) === normalizePath(sourceFilePath) ? sourceFile : void 0,
27267
+ const importedSources = /* @__PURE__ */ new Map();
27268
+ const resolveImport = input.includes("resolveVar(") ? transformOpts.resolveImport : void 0;
27269
+ const resolveViaCallback = (specifier, containingFile) => {
27270
+ let resolved = null;
27271
+ try {
27272
+ resolved = resolveImport(specifier, containingFile, { kind: "type-info" });
27273
+ } catch {}
27274
+ if (!resolved) return void 0;
27275
+ const extension = getResolvedExtension(resolved.path);
27276
+ if (!extension) return void 0;
27277
+ const resolvedFileName = normalizePath(resolved.path.split("?")[0]);
27278
+ if (resolvedFileName !== normalizePath(sourceFilePath) && !importedSources.has(resolvedFileName)) importedSources.set(resolvedFileName, ts.createSourceFile(resolvedFileName, resolved.code, tsCompilerOptions.target, true));
27279
+ return {
27280
+ resolvedFileName,
27281
+ extension,
27282
+ isExternalLibraryImport: false
27283
+ };
27284
+ };
27285
+ if (resolveImport) tsCompilerOptions.noResolve = false;
27286
+ const compilerHost = {
27287
+ getSourceFile: (fileName) => normalizePath(fileName) === normalizePath(sourceFilePath) ? sourceFile : importedSources.get(normalizePath(fileName)),
27105
27288
  writeFile: (name, text) => {
27106
27289
  if (name.endsWith(".js.map") || name.endsWith(".mjs.map")) results.map = text;
27107
27290
  else if (name.endsWith(".js") || name.endsWith(".mjs")) results.code = text;
@@ -27111,11 +27294,13 @@ const transpileModule = (config, input, transformOpts) => {
27111
27294
  getCanonicalFileName: (fileName) => fileName,
27112
27295
  getCurrentDirectory: () => transformOpts.currentDirectory || (typeof process !== "undefined" ? process.cwd() : "/"),
27113
27296
  getNewLine: () => ts.sys && ts.sys.newLine || "\n",
27114
- fileExists: (fileName) => normalizePath(fileName) === normalizePath(sourceFilePath),
27297
+ fileExists: (fileName) => normalizePath(fileName) === normalizePath(sourceFilePath) || importedSources.has(normalizePath(fileName)),
27115
27298
  readFile: () => "",
27116
27299
  directoryExists: () => true,
27117
- getDirectories: () => []
27118
- });
27300
+ getDirectories: () => [],
27301
+ ...resolveImport ? { resolveModuleNameLiterals: (moduleLiterals, containingFile) => moduleLiterals.map((literal) => ({ resolvedModule: resolveViaCallback(literal.text, containingFile) })) } : {}
27302
+ };
27303
+ const program = ts.createProgram([sourceFilePath], tsCompilerOptions, compilerHost);
27119
27304
  const typeChecker = program.getTypeChecker();
27120
27305
  const transformers = {
27121
27306
  before: [
@@ -27132,18 +27317,36 @@ const transpileModule = (config, input, transformOpts) => {
27132
27317
  }
27133
27318
  if (transformOpts.componentExport === "customelement" || transformOpts.componentExport === "module") transformers.after.push(nativeComponentTransform(compilerCtx, transformOpts, buildCtx));
27134
27319
  else transformers.after.push(lazyComponentTransform(compilerCtx, transformOpts, buildCtx));
27135
- program.emit(void 0, void 0, void 0, false, transformers);
27320
+ program.emit(sourceFile, void 0, void 0, false, transformers);
27136
27321
  if (transformOpts.buildOverrides && results.code) {
27137
27322
  const mutations = Object.entries(transformOpts.buildOverrides).filter(([, v]) => v !== void 0).map(([k, v]) => `__stencilBUILD.${k}=${v};`).join("");
27138
27323
  if (mutations) results.code = `import{BUILD as __stencilBUILD}from"${STENCIL_APP_DATA_ID}";\n${mutations}\n` + results.code;
27139
27324
  }
27140
- const tsDiagnostics = [...program.getSyntacticDiagnostics()];
27325
+ const tsDiagnostics = [...program.getSyntacticDiagnostics(sourceFile)];
27141
27326
  if (config.validateTypes) tsDiagnostics.push(...program.getOptionsDiagnostics());
27142
27327
  buildCtx.diagnostics.push(...loadTypeScriptDiagnostics(tsDiagnostics));
27143
27328
  results.diagnostics.push(...buildCtx.diagnostics);
27144
27329
  results.moduleFile = compilerCtx.moduleMap.get(results.sourceFilePath);
27145
27330
  return results;
27146
27331
  };
27332
+ /**
27333
+ * Maps a `resolveImport` result path to the TypeScript extension the program should parse it
27334
+ * as. Only TypeScript sources are taken - `noLib`/no `allowJs` means anything else would be
27335
+ * dropped by the program anyway, so it stays unresolved exactly as it did before.
27336
+ *
27337
+ * @param path the resolved path returned by the `resolveImport` callback
27338
+ * @returns the matching `ts.Extension`, or `undefined` if the file can't add type info
27339
+ */
27340
+ const getResolvedExtension = (path) => {
27341
+ const bare = path.split("?")[0];
27342
+ if (bare.endsWith(".d.ts")) return ts.Extension.Dts;
27343
+ if (bare.endsWith(".d.mts")) return ts.Extension.Dmts;
27344
+ if (bare.endsWith(".d.cts")) return ts.Extension.Dcts;
27345
+ if (bare.endsWith(".tsx")) return ts.Extension.Tsx;
27346
+ if (bare.endsWith(".mts")) return ts.Extension.Mts;
27347
+ if (bare.endsWith(".cts")) return ts.Extension.Cts;
27348
+ if (bare.endsWith(".ts")) return ts.Extension.Ts;
27349
+ };
27147
27350
  const getScriptTargetKind = (transformOpts) => {
27148
27351
  const target = transformOpts.target && transformOpts.target.toUpperCase();
27149
27352
  if (isNumber$1(ts.ScriptTarget[target])) return ts.ScriptTarget[target];