@stencil/core 2.14.0 → 2.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.
package/cli/index.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- Stencil CLI (CommonJS) v2.14.0 | MIT Licensed | https://stenciljs.com
2
+ Stencil CLI (CommonJS) v2.14.1 | MIT Licensed | https://stenciljs.com
3
3
  */
4
4
  'use strict';
5
5
 
@@ -513,7 +513,7 @@ const getNpmConfigEnvArgs = (sys) => {
513
513
  const dependencies = [
514
514
  {
515
515
  name: "@stencil/core",
516
- version: "2.14.0",
516
+ version: "2.14.1",
517
517
  main: "compiler/stencil.js",
518
518
  resources: [
519
519
  "package.json",
package/cli/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- Stencil CLI v2.14.0 | MIT Licensed | https://stenciljs.com
2
+ Stencil CLI v2.14.1 | MIT Licensed | https://stenciljs.com
3
3
  */
4
4
  const toLowerCase = (str) => str.toLowerCase();
5
5
  const dashToPascalCase = (str) => toLowerCase(str)
@@ -489,7 +489,7 @@ const getNpmConfigEnvArgs = (sys) => {
489
489
  const dependencies = [
490
490
  {
491
491
  name: "@stencil/core",
492
- version: "2.14.0",
492
+ version: "2.14.1",
493
493
  main: "compiler/stencil.js",
494
494
  resources: [
495
495
  "package.json",
package/cli/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stencil/core/cli",
3
- "version": "2.14.0",
3
+ "version": "2.14.1",
4
4
  "description": "Stencil CLI.",
5
5
  "main": "./index.cjs",
6
6
  "module": "./index.js",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stencil/core/compiler",
3
- "version": "2.14.0",
3
+ "version": "2.14.1",
4
4
  "description": "Stencil Compiler.",
5
5
  "main": "./stencil.js",
6
6
  "types": "./stencil.d.ts",
@@ -1,5 +1,5 @@
1
1
  /*!
2
- Stencil Compiler v2.14.0 | MIT Licensed | https://stenciljs.com
2
+ Stencil Compiler v2.14.1 | MIT Licensed | https://stenciljs.com
3
3
  */
4
4
  (function(exports) {
5
5
  'use strict';
@@ -3967,7 +3967,7 @@ const createCustomResolverAsync = (sys, inMemoryFs, exts) => {
3967
3967
  };
3968
3968
  };
3969
3969
 
3970
- const buildId = '20220214175725';
3970
+ const buildId = '20220307172718';
3971
3971
  const minfyJsId = 'terser5.6.1_7';
3972
3972
  const optimizeCssId = 'autoprefixer10.2.5_postcss8.2.8_7';
3973
3973
  const parse5Version = '6.0.1';
@@ -3975,8 +3975,8 @@ const rollupVersion = '2.42.3';
3975
3975
  const sizzleVersion = '2.42.3';
3976
3976
  const terserVersion = '5.6.1';
3977
3977
  const typescriptVersion = '4.5.4';
3978
- const vermoji = '💫';
3979
- const version$3 = '2.14.0';
3978
+ const vermoji = '🐦';
3979
+ const version$3 = '2.14.1';
3980
3980
  const versions = {
3981
3981
  stencil: version$3,
3982
3982
  parse5: parse5Version,
@@ -40941,9 +40941,24 @@ const createComponentExport = (cmp) => {
40941
40941
  return `export { ${originalClassName} as ${underscoredClassName} } from '${filePath}';`;
40942
40942
  };
40943
40943
 
40944
+ /**
40945
+ * Rollup plugin that aids in resolving the entry points (1 or more files) for a Stencil project. For example, a project
40946
+ * using the `dist-custom-elements` output target may have a single 'entry point' for each file containing a component.
40947
+ * Each of those files will be independently resolved and loaded by this plugin for further processing by Rollup later
40948
+ * in the bundling process.
40949
+ * @param entries the Stencil project files to process. It should be noted that the keys in this object may not
40950
+ * necessarily be an absolute or relative path to a file, but may be a Rollup Virtual Module (which begin with \0).
40951
+ * @returns the rollup plugin that loads and process a Stencil project's entry points
40952
+ */
40944
40953
  const loaderPlugin = (entries = {}) => {
40945
40954
  return {
40946
40955
  name: 'stencilLoaderPlugin',
40956
+ /**
40957
+ * A rollup build hook for resolving the imports of individual Stencil project files. This hook only resolves
40958
+ * modules that are contained in the plugin's `entries` argument. [Source](https://rollupjs.org/guide/en/#resolveid)
40959
+ * @param id the importee to resolve
40960
+ * @returns a string that resolves an import to some id, null otherwise
40961
+ */
40947
40962
  resolveId(id) {
40948
40963
  if (id in entries) {
40949
40964
  return {
@@ -40952,6 +40967,12 @@ const loaderPlugin = (entries = {}) => {
40952
40967
  }
40953
40968
  return null;
40954
40969
  },
40970
+ /**
40971
+ * A rollup build hook for loading individual Stencil project files [Source](https://rollupjs.org/guide/en/#load)
40972
+ * @param id the path of the module to load. It should be noted that the keys in this object may not necessarily
40973
+ * be an absolute or relative path to a file, but may be a Rollup Virtual Module.
40974
+ * @returns the module matched, null otherwise
40975
+ */
40955
40976
  load(id) {
40956
40977
  if (id in entries) {
40957
40978
  return entries[id];
@@ -41569,9 +41590,22 @@ const getTsResolveExtension = (p) => {
41569
41590
  };
41570
41591
  const shouldPatchRemoteTypeScript = (compilerExe) => !IS_NODE_ENV && isRemoteUrl(compilerExe);
41571
41592
 
41593
+ /**
41594
+ * Rollup plugin that aids in resolving the TypeScript files and performing the transpilation step.
41595
+ * @param compilerCtx the current compiler context
41596
+ * @param bundleOpts Rollup bundling options to apply during TypeScript compilation
41597
+ * @param config the Stencil configuration for the project
41598
+ * @returns the rollup plugin for handling TypeScript files.
41599
+ */
41572
41600
  const typescriptPlugin = (compilerCtx, bundleOpts, config) => {
41573
41601
  return {
41574
41602
  name: `${bundleOpts.id}TypescriptPlugin`,
41603
+ /**
41604
+ * A rollup build hook for loading TypeScript files and their associated source maps (if they exist).
41605
+ * [Source](https://rollupjs.org/guide/en/#load)
41606
+ * @param id the path of the file to load
41607
+ * @returns the module matched (with its sourcemap if it exists), null otherwise
41608
+ */
41575
41609
  load(id) {
41576
41610
  if (isAbsolute$1(id)) {
41577
41611
  const fsFilePath = normalizeFsPath(id);
@@ -41587,6 +41621,13 @@ const typescriptPlugin = (compilerCtx, bundleOpts, config) => {
41587
41621
  }
41588
41622
  return null;
41589
41623
  },
41624
+ /**
41625
+ * Performs TypeScript compilation/transpilation, including applying any transformations against the Abstract Syntax
41626
+ * Tree (AST) specific to stencil
41627
+ * @param _code the code to modify, unused
41628
+ * @param id module's identifier
41629
+ * @returns the transpiled code, with its associated sourcemap. null otherwise
41630
+ */
41590
41631
  transform(_code, id) {
41591
41632
  if (isAbsolute$1(id)) {
41592
41633
  const fsFilePath = normalizeFsPath(id);
@@ -53750,6 +53791,14 @@ const bundleOutput = async (config, compilerCtx, buildCtx, bundleOpts) => {
53750
53791
  }
53751
53792
  return undefined;
53752
53793
  };
53794
+ /**
53795
+ * Build the rollup options that will be used to transpile, minify, and otherwise transform a Stencil project
53796
+ * @param config the Stencil configuration for the project
53797
+ * @param compilerCtx the current compiler context
53798
+ * @param buildCtx a context object containing information about the current build
53799
+ * @param bundleOpts Rollup bundling options to apply to the base configuration setup by this function
53800
+ * @returns the rollup options to be used
53801
+ */
53753
53802
  const getRollupOptions = (config, compilerCtx, buildCtx, bundleOpts) => {
53754
53803
  var _a;
53755
53804
  const customResolveOptions = createCustomResolverAsync(config.sys, compilerCtx.fs, [
@@ -54554,11 +54603,46 @@ const addModuleMetadataProxies = (tsSourceFile, moduleFile) => {
54554
54603
  const addComponentMetadataProxy = (compilerMeta) => {
54555
54604
  return t.createStatement(createComponentMetadataProxy(compilerMeta));
54556
54605
  };
54606
+ /**
54607
+ * Create a call expression for wrapping a component in a proxy. This call expression takes a form:
54608
+ * ```ts
54609
+ * PROXY_CUSTOM_ELEMENT(ComponentClassName, Metadata);
54610
+ * ```
54611
+ * where
54612
+ * - `PROXY_CUSTOM_ELEMENT` is a Stencil internal identifier that will be replaced with the name of the actual function
54613
+ * name at compile name
54614
+ * - `ComponentClassName` is the name Stencil component's class
54615
+ * - `Metadata` is the compiler metadata associated with the Stencil component
54616
+ *
54617
+ * @param compilerMeta compiler metadata associated with the component to be wrapped in a proxy
54618
+ * @returns the generated call expression
54619
+ */
54557
54620
  const createComponentMetadataProxy = (compilerMeta) => {
54558
54621
  const compactMeta = formatComponentRuntimeMeta(compilerMeta, true);
54559
- const literalCmpClassName = t.createIdentifier(compilerMeta.componentClassName);
54622
+ const literalCmpClassName = t.factory.createIdentifier(compilerMeta.componentClassName);
54623
+ const literalMeta = convertValueToLiteral(compactMeta);
54624
+ return t.factory.createCallExpression(t.factory.createIdentifier(PROXY_CUSTOM_ELEMENT), [], [literalCmpClassName, literalMeta]);
54625
+ };
54626
+ /**
54627
+ * Create a call expression for wrapping a component represented as an anonymous class in a proxy. This call expression
54628
+ * takes a form:
54629
+ * ```ts
54630
+ * PROXY_CUSTOM_ELEMENT(Clazz, Metadata);
54631
+ * ```
54632
+ * where
54633
+ * - `PROXY_CUSTOM_ELEMENT` is a Stencil internal identifier that will be replaced with the name of the actual function
54634
+ * name at compile name
54635
+ * - `Clazz` is an anonymous class to be proxied
54636
+ * - `Metadata` is the compiler metadata associated with the Stencil component
54637
+ *
54638
+ * @param compilerMeta compiler metadata associated with the component to be wrapped in a proxy
54639
+ * @param clazz the anonymous class to proxy
54640
+ * @returns the generated call expression
54641
+ */
54642
+ const createAnonymousClassMetadataProxy = (compilerMeta, clazz) => {
54643
+ const compactMeta = formatComponentRuntimeMeta(compilerMeta, true);
54560
54644
  const literalMeta = convertValueToLiteral(compactMeta);
54561
- return t.createCall(t.createIdentifier(PROXY_CUSTOM_ELEMENT), [], [literalCmpClassName, literalMeta]);
54645
+ return t.factory.createCallExpression(t.factory.createIdentifier(PROXY_CUSTOM_ELEMENT), [], [clazz, literalMeta]);
54562
54646
  };
54563
54647
 
54564
54648
  const defineCustomElement = (tsSourceFile, moduleFile, transformOpts) => {
@@ -54833,7 +54917,7 @@ const createConstClass = (transformOpts, classNode, heritageClauses, members) =>
54833
54917
  }
54834
54918
  return t.createVariableStatement(constModifiers, t.createVariableDeclarationList([
54835
54919
  t.createVariableDeclaration(className, undefined, t.createClassExpression(classModifiers, undefined, classNode.typeParameters, heritageClauses, members)),
54836
- ], t.NodeFlags.Let));
54920
+ ], t.NodeFlags.Const));
54837
54921
  };
54838
54922
 
54839
54923
  const addCreateEvents = (moduleFile, cmp) => {
@@ -55114,16 +55198,9 @@ const addDefineCustomElementFunctions = (compilerCtx, components, outputTarget)
55114
55198
  const newStatements = [];
55115
55199
  const caseStatements = [];
55116
55200
  const tagNames = [];
55117
- addCoreRuntimeApi(moduleFile, RUNTIME_APIS.proxyCustomElement);
55118
55201
  if (moduleFile.cmps.length) {
55119
55202
  const principalComponent = moduleFile.cmps[0];
55120
55203
  tagNames.push(principalComponent.tagName);
55121
- // wraps the initial component class in a `proxyCustomElement` wrapper.
55122
- // This is what will be exported and called from the `defineCustomElement` call.
55123
- const proxyDefinition = createComponentMetadataProxy(principalComponent);
55124
- const metaExpression = t.factory.createExpressionStatement(t.factory.createBinaryExpression(t.factory.createIdentifier(principalComponent.componentClassName), t.factory.createToken(t.SyntaxKind.EqualsToken), proxyDefinition));
55125
- newStatements.push(metaExpression);
55126
- t.addSyntheticLeadingComment(proxyDefinition, t.SyntaxKind.MultiLineCommentTrivia, '@__PURE__', false);
55127
55204
  // define the current component - `customElements.define(tagName, MyProxiedComponent);`
55128
55205
  const customElementsDefineCallExpression = t.factory.createCallExpression(t.factory.createPropertyAccessExpression(t.factory.createIdentifier('customElements'), 'define'), undefined, [t.factory.createIdentifier('tagName'), t.factory.createIdentifier(principalComponent.componentClassName)]);
55129
55206
  // create a `case` block that defines the current component. We'll add them to our switch statement later.
@@ -55240,6 +55317,71 @@ function createAutoDefinitionExpression(componentName) {
55240
55317
  ]));
55241
55318
  }
55242
55319
 
55320
+ /**
55321
+ * Proxy custom elements for the `dist-custom-elements` output target. This function searches for a Stencil component's
55322
+ * class initializer (found on the righthand side of the '=' operator):
55323
+ *
55324
+ * ```ts
55325
+ * const MyComponent = class extends HTMLElement { // Implementation omitted }
55326
+ * ```
55327
+ *
55328
+ * and wraps the initializer into a `proxyCustomElement` call:
55329
+ *
55330
+ * ```ts
55331
+ * const MyComponent = proxyCustomElement(class extends HTMLElement { // Implementation omitted }, componentMetadata);
55332
+ * ```
55333
+ *
55334
+ * This is to work around an issue where treeshaking does not work for webpack users, whose details are captured in full
55335
+ * in [this issue on the webpack GitHub repo](https://github.com/webpack/webpack/issues/14963).
55336
+ *
55337
+ * @param compilerCtx current compiler context
55338
+ * @param transformOpts transpilation options for the current build
55339
+ * @returns a TypeScript AST transformer factory function that performs the above described transformation
55340
+ */
55341
+ const proxyCustomElement = (compilerCtx, transformOpts) => {
55342
+ return () => {
55343
+ return (tsSourceFile) => {
55344
+ const moduleFile = getModuleFromSourceFile(compilerCtx, tsSourceFile);
55345
+ if (!moduleFile.cmps.length) {
55346
+ return tsSourceFile;
55347
+ }
55348
+ const principalComponent = moduleFile.cmps[0];
55349
+ for (let [stmtIndex, stmt] of tsSourceFile.statements.entries()) {
55350
+ if (t.isVariableStatement(stmt)) {
55351
+ for (let [declarationIndex, declaration] of stmt.declarationList.declarations.entries()) {
55352
+ if (declaration.name.getText() !== principalComponent.componentClassName) {
55353
+ continue;
55354
+ }
55355
+ // wrap the Stencil component's class declaration in a component proxy
55356
+ const proxyCreationCall = createAnonymousClassMetadataProxy(principalComponent, declaration.initializer);
55357
+ t.addSyntheticLeadingComment(proxyCreationCall, t.SyntaxKind.MultiLineCommentTrivia, '@__PURE__', false);
55358
+ // update the component's variable declaration to use the new initializer
55359
+ const proxiedComponentDeclaration = t.factory.updateVariableDeclaration(declaration, declaration.name, declaration.exclamationToken, declaration.type, proxyCreationCall);
55360
+ // update the declaration list that contains the updated variable declaration
55361
+ const updatedDeclarationList = t.factory.updateVariableDeclarationList(stmt.declarationList, [
55362
+ ...stmt.declarationList.declarations.slice(0, declarationIndex),
55363
+ proxiedComponentDeclaration,
55364
+ ...stmt.declarationList.declarations.slice(declarationIndex + 1),
55365
+ ]);
55366
+ // update the variable statement containing the updated declaration list
55367
+ const updatedVariableStatement = t.factory.updateVariableStatement(stmt, [t.factory.createModifier(t.SyntaxKind.ExportKeyword)], updatedDeclarationList);
55368
+ // update the source file's statements to use the new variable statement
55369
+ tsSourceFile = t.factory.updateSourceFile(tsSourceFile, [
55370
+ ...tsSourceFile.statements.slice(0, stmtIndex),
55371
+ updatedVariableStatement,
55372
+ ...tsSourceFile.statements.slice(stmtIndex + 1),
55373
+ ]);
55374
+ // finally, ensure that the proxyCustomElement function is imported
55375
+ tsSourceFile = addImports(transformOpts, tsSourceFile, [RUNTIME_APIS.proxyCustomElement], transformOpts.coreImportPath);
55376
+ return tsSourceFile;
55377
+ }
55378
+ }
55379
+ }
55380
+ return tsSourceFile;
55381
+ };
55382
+ };
55383
+ };
55384
+
55243
55385
  const updateStencilCoreImports = (updatedCoreImportPath) => {
55244
55386
  return () => {
55245
55387
  return (tsSourceFile) => {
@@ -55314,19 +55456,19 @@ const bundleCustomElements$1 = async (config, compilerCtx, buildCtx, outputTarge
55314
55456
  id: 'customElements',
55315
55457
  platform: 'client',
55316
55458
  conditionals: getCustomElementsBuildConditionals(config, buildCtx.components),
55317
- customTransformers: getCustomElementBundleCustomTransformer$1(config, compilerCtx, buildCtx.components, outputTarget),
55459
+ customTransformers: getCustomElementCustomTransformer(config, compilerCtx, buildCtx.components, outputTarget),
55318
55460
  externalRuntime: !!outputTarget.externalRuntime,
55319
55461
  inlineWorkers: true,
55320
55462
  inputs: {
55321
55463
  index: '\0core',
55322
55464
  },
55323
55465
  loader: {
55324
- '\0core': generateEntryPoint$1(outputTarget, buildCtx),
55466
+ '\0core': generateEntryPoint$1(outputTarget),
55325
55467
  },
55326
55468
  inlineDynamicImports: outputTarget.inlineDynamicImports,
55327
55469
  preserveEntrySignatures: 'allow-extension',
55328
55470
  };
55329
- addCustomElementInputs(outputTarget, buildCtx, bundleOpts);
55471
+ addCustomElementInputs(buildCtx, bundleOpts);
55330
55472
  const build = await bundleOutput(config, compilerCtx, buildCtx, bundleOpts);
55331
55473
  if (build) {
55332
55474
  const rollupOutput = await build.generate({
@@ -55372,7 +55514,12 @@ const bundleCustomElements$1 = async (config, compilerCtx, buildCtx, outputTarge
55372
55514
  catchError(buildCtx.diagnostics, e);
55373
55515
  }
55374
55516
  };
55375
- const addCustomElementInputs = (_outputTarget, buildCtx, bundleOpts) => {
55517
+ /**
55518
+ * Create the virtual modules/input modules for the `dist-custom-elements` output target.
55519
+ * @param buildCtx the context for the current build
55520
+ * @param bundleOpts the bundle options to store the virtual modules under. acts as an output parameter
55521
+ */
55522
+ const addCustomElementInputs = (buildCtx, bundleOpts) => {
55376
55523
  const components = buildCtx.components;
55377
55524
  components.forEach((cmp) => {
55378
55525
  const exp = [];
@@ -55384,6 +55531,7 @@ const addCustomElementInputs = (_outputTarget, buildCtx, bundleOpts) => {
55384
55531
  exp.push(`export { ${importName} as ${exportName} } from '${cmp.sourceFilePath}';`);
55385
55532
  }
55386
55533
  else {
55534
+ // the `importName` may collide with the `exportName`, alias it just in case it does with `importAs`
55387
55535
  exp.push(`import { ${importName} as ${importAs}, defineCustomElement as cmpDefCustomEle } from '${cmp.sourceFilePath}';`);
55388
55536
  exp.push(`export const ${exportName} = ${importAs};`);
55389
55537
  exp.push(`export const defineCustomElement = cmpDefCustomEle;`);
@@ -55392,16 +55540,29 @@ const addCustomElementInputs = (_outputTarget, buildCtx, bundleOpts) => {
55392
55540
  bundleOpts.loader[coreKey] = exp.join('\n');
55393
55541
  });
55394
55542
  };
55395
- const generateEntryPoint$1 = (outputTarget, _buildCtx) => {
55543
+ /**
55544
+ * Generate the entrypoint (`index.ts` file) contents for the `dist-custom-elements` output target
55545
+ * @param outputTarget the output target's configuration
55546
+ * @returns the stringified contents to be placed in the entrypoint
55547
+ */
55548
+ const generateEntryPoint$1 = (outputTarget) => {
55396
55549
  const imp = [];
55397
- const exp = [];
55398
55550
  imp.push(`export { setAssetPath, setPlatformOptions } from '${STENCIL_INTERNAL_CLIENT_ID}';`, `export * from '${USER_INDEX_ENTRY_ID}';`);
55399
55551
  if (outputTarget.includeGlobalScripts !== false) {
55400
55552
  imp.push(`import { globalScripts } from '${STENCIL_APP_GLOBALS_ID}';`, `globalScripts();`);
55401
55553
  }
55402
- return [...imp, ...exp].join('\n') + '\n';
55554
+ return imp.join('\n') + '\n';
55403
55555
  };
55404
- const getCustomElementBundleCustomTransformer$1 = (config, compilerCtx, components, outputTarget) => {
55556
+ /**
55557
+ * Get the series of custom transformers that will be applied to a Stencil project's source code during the TypeScript
55558
+ * transpilation process
55559
+ * @param config the configuration for the Stencil project
55560
+ * @param compilerCtx the current compiler context
55561
+ * @param components the components that will be compiled as a part of the current build
55562
+ * @param outputTarget the output target configuration
55563
+ * @returns a list of transformers to use in the transpilation process
55564
+ */
55565
+ const getCustomElementCustomTransformer = (config, compilerCtx, components, outputTarget) => {
55405
55566
  const transformOpts = {
55406
55567
  coreImportPath: STENCIL_INTERNAL_CLIENT_ID,
55407
55568
  componentExport: null,
@@ -55415,6 +55576,7 @@ const getCustomElementBundleCustomTransformer$1 = (config, compilerCtx, componen
55415
55576
  addDefineCustomElementFunctions(compilerCtx, components, outputTarget),
55416
55577
  updateStencilCoreImports(transformOpts.coreImportPath),
55417
55578
  nativeComponentTransform(compilerCtx, transformOpts),
55579
+ proxyCustomElement(compilerCtx, transformOpts),
55418
55580
  removeCollectionImports(compilerCtx),
55419
55581
  ];
55420
55582
  };
@@ -63816,7 +63978,7 @@ const getComponentPathContent = (componentGraph, outputTarget) => {
63816
63978
  const dependencies = [
63817
63979
  {
63818
63980
  name: "@stencil/core",
63819
- version: "2.14.0",
63981
+ version: "2.14.1",
63820
63982
  main: "compiler/stencil.js",
63821
63983
  resources: [
63822
63984
  "package.json",
@@ -65002,7 +65164,7 @@ const validateTesting = (config, diagnostics) => {
65002
65164
  testing.pixelmatchThreshold = DEFAULT_PIXEL_MATCH_THRESHOLD;
65003
65165
  }
65004
65166
  if (testing.testRegex === undefined) {
65005
- testing.testRegex = '(/__tests__/.*|\\.?(test|spec|e2e))\\.(tsx?|ts?|jsx?|js?)$';
65167
+ testing.testRegex = '(/__tests__/.*|\\.(test|spec|e2e))\\.(tsx|ts|jsx|js)$';
65006
65168
  }
65007
65169
  if (Array.isArray(testing.testMatch)) {
65008
65170
  delete testing.testRegex;