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 10, 2023
1 parent abfc52e commit 3d812d5
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 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,13 @@ 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 `babelTransform` function execution
// 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.
// So we need to replace ' - ' with '-' to fix this issue.
return babelTransform({ code, visitor, stripTypes })?.code?.replace(' - ', '-') || '';
}

// 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

0 comments on commit 3d812d5

Please sign in to comment.