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 Jan 4, 2024
1 parent 198ad21 commit e05a9eb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
3 changes: 2 additions & 1 deletion packages/core/src/generators/react/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import traverse from 'traverse';
import { ToReactOptions } from './types';

export const processBinding = (str: string, options: ToReactOptions) => {
if (options.stateType !== 'useState') {
// fix web-component tag transform issue with dashes by not transforming it
if (options.stateType !== 'useState' || str.includes('-')) {
return str;
}

Expand Down
8 changes: 6 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,12 @@ export const createCodeProcessorPlugin =
}
}

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

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

Please sign in to comment.