Skip to content

Commit 1d79672

Browse files
authoredJul 13, 2023
fix(compiler): sourcemap errors for dist-custom-elements + dist-hydrate-script (#4527)
this commit fixes an issue where a stencil project that use both the `dist-custom-elements` and `dist-hydrate-script` output targets would see the following error when building their project (with sourcemaps enabled): ``` [ WARN ] Bundling Warning SOURCEMAP_ERROR Error when using sourcemap for reporting an error: Can't resolve original location of error. ``` this commit resolves this error by ensuring the `HTMLElement` core runtime API used by `dist-custom-elements` no longer interferese with the generated code for `dist-hydrate-script`. this is accomplished by using the output-target-specific runtime api slots introduced in #4200. this prevents the `HTMLElement` import from polluting the sourcemaps/source used in the `dist-hydrate-script` target
1 parent 5f436af commit 1d79672

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed
 

‎src/compiler/transformers/component-native/native-component.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
import { DIST_CUSTOM_ELEMENTS } from '@utils';
12
import ts from 'typescript';
23

34
import type * as d from '../../../declarations';
4-
import { addCoreRuntimeApi, HTML_ELEMENT, RUNTIME_APIS } from '../core-runtime-apis';
5+
import { addOutputTargetCoreRuntimeApi, HTML_ELEMENT, RUNTIME_APIS } from '../core-runtime-apis';
56
import { transformHostData } from '../host-data-transform';
67
import { removeStaticMetaProperties } from '../remove-static-meta-properties';
78
import { updateComponentClass } from '../update-component-class';
@@ -40,7 +41,7 @@ const updateNativeHostComponentHeritageClauses = (
4041

4142
if (moduleFile.cmps.length >= 1) {
4243
// we'll need to import `HTMLElement` in order to extend it
43-
addCoreRuntimeApi(moduleFile, RUNTIME_APIS.HTMLElement);
44+
addOutputTargetCoreRuntimeApi(moduleFile, DIST_CUSTOM_ELEMENTS, RUNTIME_APIS.HTMLElement);
4445
}
4546

4647
const heritageClause = ts.factory.createHeritageClause(ts.SyntaxKind.ExtendsKeyword, [

‎src/compiler/transformers/test/native-constructor.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ describe('nativeComponentTransform', () => {
3838
const transpiledModule = transpileModule(code, null, compilerCtx, [], [transformer]);
3939

4040
expect(transpiledModule.outputText).toContain(
41-
`import { HTMLElement, defineCustomElement as __stencil_defineCustomElement, attachShadow as __stencil_attachShadow } from "@stencil/core";`
41+
`import { defineCustomElement as __stencil_defineCustomElement, HTMLElement, attachShadow as __stencil_attachShadow } from "@stencil/core";`
4242
);
4343
expect(transpiledModule.outputText).toContain(`this.__attachShadow()`);
4444
});
@@ -63,7 +63,7 @@ describe('nativeComponentTransform', () => {
6363
const transpiledModule = transpileModule(code, null, compilerCtx, [], [transformer]);
6464

6565
expect(transpiledModule.outputText).toContain(
66-
`import { HTMLElement, defineCustomElement as __stencil_defineCustomElement, attachShadow as __stencil_attachShadow } from "@stencil/core";`
66+
`import { defineCustomElement as __stencil_defineCustomElement, HTMLElement, attachShadow as __stencil_attachShadow } from "@stencil/core";`
6767
);
6868
expect(transpiledModule.outputText).toContain(`this.__attachShadow()`);
6969
});

0 commit comments

Comments
 (0)
Please sign in to comment.