Skip to content

Commit

Permalink
fix: fix web-component tag name transform issue
Browse files Browse the repository at this point in the history
  • Loading branch information
rqzheng2015 committed Dec 12, 2023
1 parent abfc52e commit 4193f2c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
7 changes: 6 additions & 1 deletion packages/core/src/helpers/babel-transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,12 @@ export const babelTransformCode = <VisitorContextType = any>(
code: string,
visitor?: Visitor<VisitorContextType>,
stripTypes = false,
) => babelTransform({ code, visitor, stripTypes })?.code || '';
) => {
// Fix web component tag issue due to the babel transform
// For exmaple: we pass a tag called "swiper-container", and it will be renamed as "swiper - container" after babel transforming,
// because babel will automatically identify the "-" as an operator, and add a space before and after it.
return babelTransform({ code, visitor, stripTypes })?.code || '';
};

// Babel adds trailing semicolons, but for expressions we need those gone
// TODO: maybe detect if the original code ended with one, and keep it if so, for the case
Expand Down
6 changes: 4 additions & 2 deletions packages/core/src/helpers/plugins/process-code/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,10 @@ export const createCodeProcessorPlugin =
}
}

const result = codeProcessor('dynamic-jsx-elements', json)(node.name, '');

// const result = codeProcessor('dynamic-jsx-elements', json)(node.name, '');
const result = node.name.includes('-')
? node.name
: codeProcessor('dynamic-jsx-elements', json)(node.name, '');
if (typeof result === 'string') {
node.name = result;
} else {
Expand Down

0 comments on commit 4193f2c

Please sign in to comment.