Skip to content

Commit 7da9066

Browse files
committed
hotfix: duplicate identifiers
1 parent c0e07d8 commit 7da9066

File tree

8 files changed

+35
-17
lines changed

8 files changed

+35
-17
lines changed

packages/compiler/plugin.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { createUnplugin } from 'unplugin';
33
import { transformAsync } from '@babel/core';
44
import pluginSyntaxJsx from '@babel/plugin-syntax-jsx';
55
import pluginSyntaxTypescript from '@babel/plugin-syntax-typescript';
6-
import { dim, magenta } from 'kleur/colors';
6+
import { dim, magenta, bold, cyan } from 'kleur/colors';
77
import { visitor as legacyVdomVisitor } from './vdom';
88
import {
99
callExpressionVisitor as reactCallExpressionVisitor,
@@ -31,10 +31,18 @@ export const intro = () => {
3131
if (hasIntroRan) return;
3232
hasIntroRan = true;
3333

34+
const tips = [
35+
`use ${dim('// million-ignore')} for errors`,
36+
`use { threshold: ? } to adjust optimization sensitivity (default=0.1)`,
37+
`use { mute: true } to disable info logs`,
38+
];
39+
3440
// eslint-disable-next-line no-console
35-
console.log(`\n ${magenta(`⚡ Million.js ${process.env.VERSION || ''}`)}
36-
- Tip: use ${dim('// million-ignore')} for errors
37-
- Hotline: https://million.dev/hotline\n`);
41+
console.log(`\n ${bold(
42+
magenta(`⚡ Million.js ${process.env.VERSION || ''}`),
43+
)}
44+
- Tip: ${tips[Math.floor(Math.random() * tips.length)] as string}
45+
- Hotline: ${cyan('https://million.dev/hotline')}\n`);
3846
};
3947

4048
export const unplugin = createUnplugin((options: Options) => {

packages/compiler/react/call-expression-visitor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,8 @@ export const callExpressionVisitor = (
235235
t.isFunctionExpression(forwardRefComponent) ||
236236
t.isArrowFunctionExpression(forwardRefComponent)
237237
) {
238-
const anonymousComponentId =
239-
componentDeclarationPath.scope.generateUidIdentifier('anonymous$');
238+
const unique = getUniqueId();
239+
const anonymousComponentId = t.identifier(`M${unique}`);
240240
componentDeclarationPath.parentPath.insertBefore(
241241
t.variableDeclaration('const', [
242242
t.variableDeclarator(

packages/compiler/react/component-visitor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export const componentVisitor = (options: Options = {}, isReact = true) => {
8787
if (comment?.value.includes('million-ignore')) {
8888
// eslint-disable-next-line no-console
8989
console.log(
90-
dim(`${yellow(`<${rawComponent.id.name}>`)} was ignored.`),
90+
dim(`${yellow(`<${rawComponent.id.name}>`)} was ignored`),
9191
);
9292
return;
9393
}
@@ -247,7 +247,7 @@ export const componentVisitor = (options: Options = {}, isReact = true) => {
247247
`${yellow(`<${rawComponent.id.name}>`)} now renders ${green(
248248
underline(`~${improvementFormatted}%`),
249249
)} faster`,
250-
' ⚡',
250+
' ⚡ ',
251251
),
252252
);
253253
}

packages/compiler/react/transform.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -458,8 +458,14 @@ export const transformComponent = (
458458
* const master = (props) => {
459459
* ```
460460
*/
461-
Component.id = masterComponentId;
462461

462+
if (
463+
t.isIdentifier(Component.id) &&
464+
Component.id.name === masterComponentId.name
465+
) {
466+
masterComponentId.name = `${masterComponentId.name}_${getUniqueId()}`;
467+
}
468+
Component.id = masterComponentId;
463469
callSitePath.replaceWith(masterComponentId);
464470

465471
globalPath.insertBefore(
@@ -473,7 +479,10 @@ export const transformComponent = (
473479
t.expressionStatement(
474480
t.assignmentExpression(
475481
'=',
476-
t.memberExpression(masterComponentId, t.identifier('callable')),
482+
t.memberExpression(
483+
masterComponentId,
484+
t.identifier('__block_callable__'),
485+
),
477486
t.booleanLiteral(true),
478487
),
479488
),

packages/compiler/react/utils.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,8 @@ export const createError = (message: string, path: NodePath, file: string) => {
9494
);
9595
};
9696

97-
export const stylePrimaryMessage = (message: string, comment: string) => {
98-
return `\n🦁 ${bgMagenta(' million ')} ${magenta(message)} \n${comment}\n`;
99-
};
100-
10197
export const styleSecondaryMessage = (message: string, emoticon: string) => {
102-
return `${magenta(emoticon)} ${message}`;
98+
return `${magenta(emoticon)}${message}`;
10399
};
104100

105101
export const styleLinks = (message: string) => {

packages/react/for.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,10 @@ const createChildren = <T>(
121121
continue;
122122
}
123123

124-
if (typeof vnode.type === 'function' && 'callable' in vnode.type) {
124+
if (
125+
typeof vnode.type === 'function' &&
126+
'__block_callable__' in vnode.type
127+
) {
125128
const puppetComponent = vnode.type(vnode.props);
126129
if (MapHas$.call(REGISTRY, puppetComponent.type)) {
127130
const puppetBlock = MapGet$.call(REGISTRY, puppetComponent.type)!;

packages/react/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export const renderReactScope = (
5353
if (
5454
isValidElement(vnode) &&
5555
typeof vnode.type === 'function' &&
56-
'callable' in vnode.type
56+
'__block_callable__' in vnode.type
5757
) {
5858
const puppetComponent = (vnode.type as any)(vnode.props);
5959
if (REGISTRY.has(puppetComponent.type)) {

pnpm-lock.yaml

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)