Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(compiler): fix generated import statement #5419

Merged
merged 5 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/compiler/output-targets/dist-custom-elements/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,7 @@ export const addCustomElementInputs = (

if (cmp.isPlain) {
exp.push(`export { ${importName} as ${exportName} } from '${cmp.sourceFilePath}';`);
// TODO(STENCIL-855): Invalid syntax generation, note the unbalanced left curly brace
indexExports.push(`export { {${exportName} } from '${coreKey}';`);
indexExports.push(`export { ${exportName} } from '${coreKey}';`);
} else {
// the `importName` may collide with the `exportName`, alias it just in case it does with `importAs`
exp.push(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import type * as d from '@stencil/core/declarations';
import { mockBuildCtx } from '@stencil/core/testing';

import { BundleOptions } from '../../../bundle/bundle-interface';
import { stubComponentCompilerMeta } from '../../../types/tests/ComponentCompilerMeta.stub';
import { addCustomElementInputs } from '../index';
christian-bromann marked this conversation as resolved.
Show resolved Hide resolved

describe('dist-custom-elements', () => {
it('should export plain component', () => {
const cmpMeta = stubComponentCompilerMeta({ isPlain: true, sourceFilePath: './foo/bar.tsx', tagName: 'my-tag' });
const buildCtx = mockBuildCtx();
buildCtx.components = [cmpMeta];
const bundleOpts: BundleOptions = {
id: 'customElements',
platform: 'client',
inputs: {},
loader: {},
};
const outputTarget: d.OutputTargetDistCustomElements = {
type: 'dist-custom-elements',
customElementsExportBehavior: 'single-export-module',
};
addCustomElementInputs(buildCtx, bundleOpts, outputTarget);
expect(bundleOpts.loader['\x00MyTag']).toContain(
'export { StubCmp as MyTag } from \'./foo/bar.tsx\';')
expect(bundleOpts.loader['\x00core']).toContain(
`export { MyTag } from '\x00MyTag';\n`);
});

it('should export component with a defineCustomElement function', () => {
const cmpMeta = stubComponentCompilerMeta({ sourceFilePath: './foo/bar.tsx', tagName: 'my-tag' });
const buildCtx = mockBuildCtx();
buildCtx.components = [cmpMeta];
const bundleOpts: BundleOptions = {
id: 'customElements',
platform: 'client',
inputs: {},
loader: {},
};
const outputTarget: d.OutputTargetDistCustomElements = {
type: 'dist-custom-elements',
customElementsExportBehavior: 'single-export-module',
};
addCustomElementInputs(buildCtx, bundleOpts, outputTarget);
expect(bundleOpts.loader['\x00MyTag']).toContain(
'export const defineCustomElement = cmpDefCustomEle;')
expect(bundleOpts.loader['\x00MyTag']).toContain(
'import { StubCmp as $CmpMyTag, defineCustomElement as cmpDefCustomEle } from \'./foo/bar.tsx\';')
expect(bundleOpts.loader['\x00core']).toContain(
`export { MyTag, defineCustomElement as defineCustomElementMyTag } from '\x00MyTag';\n`);
})
});
Loading