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(bundle-utils): fallback code generation for SFC #243

Merged
merged 2 commits into from Mar 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 9 additions & 6 deletions packages/bundle-utils/src/js.ts
Expand Up @@ -161,12 +161,7 @@ function generateNode(
useClassComponent
} = options

// prettier-ignore
const componentNamespace = bridge
? `Component.options`
: useClassComponent
? `Component.__o`
: `Component`
const componentNamespace = '_Component'

walk(node, {
/**
Expand Down Expand Up @@ -194,6 +189,14 @@ function generateNode(
: `export default`
generator.push(`${exportSyntax} function (Component) {`)
generator.indent()
// prettier-ignore
const componentVariable = bridge
? `Component.options || Component`
: useClassComponent
? `Component.__o || Component`
: `Component`
// prettier-ignore
generator.pushline(`const ${componentNamespace} = ${componentVariable}`)
generator.pushline(
`${componentNamespace}.${variableName} = ${componentNamespace}.${variableName} || []`
)
Expand Down
15 changes: 9 additions & 6 deletions packages/bundle-utils/src/json.ts
Expand Up @@ -126,12 +126,7 @@ function generateNode(
useClassComponent
} = options

// prettier-ignore
const componentNamespace = bridge
? `Component.options`
: useClassComponent
? `Component.__o`
: `Component`
const componentNamespace = '_Component'

traverseNodes(node, {
enterNode(node: JSONNode, parent: JSONNode) {
Expand All @@ -152,6 +147,14 @@ function generateNode(
: `export default`
generator.push(`${exportSyntax} function (Component) {`)
generator.indent()
// prettier-ignore
const componentVariable = bridge
? `Component.options || Component`
: useClassComponent
? `Component.__o || Component`
: `Component`
// prettier-ignore
generator.pushline(`const ${componentNamespace} = ${componentVariable}`)
generator.pushline(
`${componentNamespace}.${variableName} = ${componentNamespace}.${variableName} || []`
)
Expand Down
15 changes: 9 additions & 6 deletions packages/bundle-utils/src/yaml.ts
Expand Up @@ -116,12 +116,7 @@ function generateNode(
useClassComponent
} = options

// prettier-ignore
const componentNamespace = bridge
? `Component.options`
: useClassComponent
? `Component.__o`
: `Component`
const componentNamespace = '_Component'

traverseNodes(node, {
enterNode(node: YAMLNode, parent: YAMLNode) {
Expand All @@ -141,6 +136,14 @@ function generateNode(
: `export default`
generator.push(`${exportSyntax} function (Component) {`)
generator.indent()
// prettier-ignore
const componentVariable = bridge
? `Component.options || Component`
: useClassComponent
? `Component.__o || Component`
: `Component`
// prettier-ignore
generator.pushline(`const ${componentNamespace} = ${componentVariable}`)
generator.pushline(
`${componentNamespace}.${variableName} = ${componentNamespace}.${variableName} || []`
)
Expand Down
37 changes: 21 additions & 16 deletions packages/bundle-utils/test/generator/__snapshots__/js.test.ts.snap
Expand Up @@ -193,8 +193,9 @@ Node {

exports[`array basic: code 1`] = `
"export default function (Component) {
Component.__i18n = Component.__i18n || []
Component.__i18n.push({
const _Component = Component
_Component.__i18n = _Component.__i18n || []
_Component.__i18n.push({
\\"locale\\": \\"\\",
\\"resource\\": {
\\"foo\\": [
Expand Down Expand Up @@ -224,8 +225,9 @@ Object {

exports[`array mixed: code 1`] = `
"export default function (Component) {
Component.__i18n = Component.__i18n || []
Component.__i18n.push({
const _Component = Component
_Component.__i18n = _Component.__i18n || []
_Component.__i18n.push({
\\"locale\\": \\"\\",
\\"resource\\": {
\\"foo\\": [
Expand Down Expand Up @@ -280,8 +282,9 @@ Object {

exports[`bridge with ESM exporting: code 1`] = `
"export default function (Component) {
Component.options.__i18n = Component.options.__i18n || []
Component.options.__i18n.push({
const _Component = Component.options || Component
_Component.__i18n = _Component.__i18n || []
_Component.__i18n.push({
\\"locale\\": \\"\\",
\\"resource\\": {
\\"hi\\": (()=>{const fn=(ctx) => {const { normalize: _normalize } = ctx;return _normalize([\\"hi there!\\"])};fn.source=\\"hi there!\\";return fn;})(),
Expand Down Expand Up @@ -315,9 +318,9 @@ exports[`bridge with ESM exporting: code 1`] = `
}
}
})
Component.options.__i18nBridge = Component.options.__i18nBridge || []
Component.options.__i18nBridge.push('\\"{\\\\\\\\n \\\\\\\\\\"hi\\\\\\\\\\": \\\\\\\\\\"hi there!\\\\\\\\\\",\\\\\\\\n \\\\\\\\\\"nested\\\\\\\\\\": {\\\\\\\\n \\\\\\\\\\"hello\\\\\\\\\\": \\\\\\\\\\"hello world!\\\\\\\\\\",\\\\\\\\n \\\\\\\\\\"more\\\\\\\\\\": {\\\\\\\\n \\\\\\\\\\"plural\\\\\\\\\\": \\\\\\\\\\"@.caml:{\\\\u0027no apples\\\\u0027} | {0} apple | {n} apples\\\\\\\\\\"\\\\\\\\n },\\\\\\\\n \\\\\\\\\\"list\\\\\\\\\\": \\\\\\\\\\"hi, {0} !\\\\\\\\\\"\\\\\\\\n },\\\\\\\\n \\\\\\\\\\"こんにちは\\\\\\\\\\": \\\\\\\\\\"こんにちは!\\\\\\\\\\",\\\\\\\\n \\\\\\\\\\"single-quote\\\\\\\\\\": \\\\\\\\\\"I don\\\\u0027t know!\\\\\\\\\\",\\\\\\\\n \\\\\\\\\\"emoji\\\\\\\\\\": \\\\\\\\\\"😺\\\\\\\\\\",\\\\\\\\n \\\\\\\\\\"unicode\\\\\\\\\\": \\\\\\\\\\"\\\\\\\\\\\\\\\\u0041\\\\\\\\\\",\\\\\\\\n \\\\\\\\\\"unicode-escape\\\\\\\\\\": \\\\\\\\\\"\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\u0041\\\\\\\\\\",\\\\\\\\n \\\\\\\\\\"backslash-single-quote\\\\\\\\\\": \\\\\\\\\\"\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\u0027\\\\\\\\\\",\\\\\\\\n \\\\\\\\\\"backslash-backslash\\\\\\\\\\": \\\\\\\\\\"\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\",\\\\\\\\n \\\\\\\\\\"errors\\\\\\\\\\": [\\\\\\\\\\"ERROR1001\\\\\\\\\\", \\\\\\\\\\"ERROR1002\\\\\\\\\\"],\\\\\\\\n \\\\\\\\\\"complex\\\\\\\\\\": {\\\\\\\\n \\\\\\\\\\"warnings\\\\\\\\\\": [\\\\\\\\n \\\\\\\\\\"NOTE: This is warning\\\\\\\\\\",\\\\\\\\n {\\\\\\\\n \\\\\\\\\\"named-waring\\\\\\\\\\": \\\\\\\\\\"this is {type} warining\\\\\\\\\\"\\\\\\\\n }\\\\\\\\n ]\\\\\\\\n }\\\\\\\\n}\\\\\\\\n\\"')
delete Component.options._Ctor
_Component.__i18nBridge = _Component.__i18nBridge || []
_Component.__i18nBridge.push('\\"{\\\\\\\\n \\\\\\\\\\"hi\\\\\\\\\\": \\\\\\\\\\"hi there!\\\\\\\\\\",\\\\\\\\n \\\\\\\\\\"nested\\\\\\\\\\": {\\\\\\\\n \\\\\\\\\\"hello\\\\\\\\\\": \\\\\\\\\\"hello world!\\\\\\\\\\",\\\\\\\\n \\\\\\\\\\"more\\\\\\\\\\": {\\\\\\\\n \\\\\\\\\\"plural\\\\\\\\\\": \\\\\\\\\\"@.caml:{\\\\u0027no apples\\\\u0027} | {0} apple | {n} apples\\\\\\\\\\"\\\\\\\\n },\\\\\\\\n \\\\\\\\\\"list\\\\\\\\\\": \\\\\\\\\\"hi, {0} !\\\\\\\\\\"\\\\\\\\n },\\\\\\\\n \\\\\\\\\\"こんにちは\\\\\\\\\\": \\\\\\\\\\"こんにちは!\\\\\\\\\\",\\\\\\\\n \\\\\\\\\\"single-quote\\\\\\\\\\": \\\\\\\\\\"I don\\\\u0027t know!\\\\\\\\\\",\\\\\\\\n \\\\\\\\\\"emoji\\\\\\\\\\": \\\\\\\\\\"😺\\\\\\\\\\",\\\\\\\\n \\\\\\\\\\"unicode\\\\\\\\\\": \\\\\\\\\\"\\\\\\\\\\\\\\\\u0041\\\\\\\\\\",\\\\\\\\n \\\\\\\\\\"unicode-escape\\\\\\\\\\": \\\\\\\\\\"\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\u0041\\\\\\\\\\",\\\\\\\\n \\\\\\\\\\"backslash-single-quote\\\\\\\\\\": \\\\\\\\\\"\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\u0027\\\\\\\\\\",\\\\\\\\n \\\\\\\\\\"backslash-backslash\\\\\\\\\\": \\\\\\\\\\"\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\",\\\\\\\\n \\\\\\\\\\"errors\\\\\\\\\\": [\\\\\\\\\\"ERROR1001\\\\\\\\\\", \\\\\\\\\\"ERROR1002\\\\\\\\\\"],\\\\\\\\n \\\\\\\\\\"complex\\\\\\\\\\": {\\\\\\\\n \\\\\\\\\\"warnings\\\\\\\\\\": [\\\\\\\\n \\\\\\\\\\"NOTE: This is warning\\\\\\\\\\",\\\\\\\\n {\\\\\\\\n \\\\\\\\\\"named-waring\\\\\\\\\\": \\\\\\\\\\"this is {type} warining\\\\\\\\\\"\\\\\\\\n }\\\\\\\\n ]\\\\\\\\n }\\\\\\\\n}\\\\\\\\n\\"')
delete _Component._Ctor

}
"
Expand All @@ -334,8 +337,9 @@ Object {

exports[`bridge: code 1`] = `
"module.exports = function (Component) {
Component.options.__i18n = Component.options.__i18n || []
Component.options.__i18n.push({
const _Component = Component.options || Component
_Component.__i18n = _Component.__i18n || []
_Component.__i18n.push({
\\"locale\\": \\"\\",
\\"resource\\": {
\\"hi\\": (()=>{const fn=(ctx) => {const { normalize: _normalize } = ctx;return _normalize([\\"hi there!\\"])};fn.source=\\"hi there!\\";return fn;})(),
Expand Down Expand Up @@ -369,9 +373,9 @@ exports[`bridge: code 1`] = `
}
}
})
Component.options.__i18nBridge = Component.options.__i18nBridge || []
Component.options.__i18nBridge.push('\\"{\\\\\\\\n \\\\\\\\\\"hi\\\\\\\\\\": \\\\\\\\\\"hi there!\\\\\\\\\\",\\\\\\\\n \\\\\\\\\\"nested\\\\\\\\\\": {\\\\\\\\n \\\\\\\\\\"hello\\\\\\\\\\": \\\\\\\\\\"hello world!\\\\\\\\\\",\\\\\\\\n \\\\\\\\\\"more\\\\\\\\\\": {\\\\\\\\n \\\\\\\\\\"plural\\\\\\\\\\": \\\\\\\\\\"@.caml:{\\\\u0027no apples\\\\u0027} | {0} apple | {n} apples\\\\\\\\\\"\\\\\\\\n },\\\\\\\\n \\\\\\\\\\"list\\\\\\\\\\": \\\\\\\\\\"hi, {0} !\\\\\\\\\\"\\\\\\\\n },\\\\\\\\n \\\\\\\\\\"こんにちは\\\\\\\\\\": \\\\\\\\\\"こんにちは!\\\\\\\\\\",\\\\\\\\n \\\\\\\\\\"single-quote\\\\\\\\\\": \\\\\\\\\\"I don\\\\u0027t know!\\\\\\\\\\",\\\\\\\\n \\\\\\\\\\"emoji\\\\\\\\\\": \\\\\\\\\\"😺\\\\\\\\\\",\\\\\\\\n \\\\\\\\\\"unicode\\\\\\\\\\": \\\\\\\\\\"\\\\\\\\\\\\\\\\u0041\\\\\\\\\\",\\\\\\\\n \\\\\\\\\\"unicode-escape\\\\\\\\\\": \\\\\\\\\\"\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\u0041\\\\\\\\\\",\\\\\\\\n \\\\\\\\\\"backslash-single-quote\\\\\\\\\\": \\\\\\\\\\"\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\u0027\\\\\\\\\\",\\\\\\\\n \\\\\\\\\\"backslash-backslash\\\\\\\\\\": \\\\\\\\\\"\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\",\\\\\\\\n \\\\\\\\\\"errors\\\\\\\\\\": [\\\\\\\\\\"ERROR1001\\\\\\\\\\", \\\\\\\\\\"ERROR1002\\\\\\\\\\"],\\\\\\\\n \\\\\\\\\\"complex\\\\\\\\\\": {\\\\\\\\n \\\\\\\\\\"warnings\\\\\\\\\\": [\\\\\\\\n \\\\\\\\\\"NOTE: This is warning\\\\\\\\\\",\\\\\\\\n {\\\\\\\\n \\\\\\\\\\"named-waring\\\\\\\\\\": \\\\\\\\\\"this is {type} warining\\\\\\\\\\"\\\\\\\\n }\\\\\\\\n ]\\\\\\\\n }\\\\\\\\n}\\\\\\\\n\\"')
delete Component.options._Ctor
_Component.__i18nBridge = _Component.__i18nBridge || []
_Component.__i18nBridge.push('\\"{\\\\\\\\n \\\\\\\\\\"hi\\\\\\\\\\": \\\\\\\\\\"hi there!\\\\\\\\\\",\\\\\\\\n \\\\\\\\\\"nested\\\\\\\\\\": {\\\\\\\\n \\\\\\\\\\"hello\\\\\\\\\\": \\\\\\\\\\"hello world!\\\\\\\\\\",\\\\\\\\n \\\\\\\\\\"more\\\\\\\\\\": {\\\\\\\\n \\\\\\\\\\"plural\\\\\\\\\\": \\\\\\\\\\"@.caml:{\\\\u0027no apples\\\\u0027} | {0} apple | {n} apples\\\\\\\\\\"\\\\\\\\n },\\\\\\\\n \\\\\\\\\\"list\\\\\\\\\\": \\\\\\\\\\"hi, {0} !\\\\\\\\\\"\\\\\\\\n },\\\\\\\\n \\\\\\\\\\"こんにちは\\\\\\\\\\": \\\\\\\\\\"こんにちは!\\\\\\\\\\",\\\\\\\\n \\\\\\\\\\"single-quote\\\\\\\\\\": \\\\\\\\\\"I don\\\\u0027t know!\\\\\\\\\\",\\\\\\\\n \\\\\\\\\\"emoji\\\\\\\\\\": \\\\\\\\\\"😺\\\\\\\\\\",\\\\\\\\n \\\\\\\\\\"unicode\\\\\\\\\\": \\\\\\\\\\"\\\\\\\\\\\\\\\\u0041\\\\\\\\\\",\\\\\\\\n \\\\\\\\\\"unicode-escape\\\\\\\\\\": \\\\\\\\\\"\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\u0041\\\\\\\\\\",\\\\\\\\n \\\\\\\\\\"backslash-single-quote\\\\\\\\\\": \\\\\\\\\\"\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\u0027\\\\\\\\\\",\\\\\\\\n \\\\\\\\\\"backslash-backslash\\\\\\\\\\": \\\\\\\\\\"\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\",\\\\\\\\n \\\\\\\\\\"errors\\\\\\\\\\": [\\\\\\\\\\"ERROR1001\\\\\\\\\\", \\\\\\\\\\"ERROR1002\\\\\\\\\\"],\\\\\\\\n \\\\\\\\\\"complex\\\\\\\\\\": {\\\\\\\\n \\\\\\\\\\"warnings\\\\\\\\\\": [\\\\\\\\n \\\\\\\\\\"NOTE: This is warning\\\\\\\\\\",\\\\\\\\n {\\\\\\\\n \\\\\\\\\\"named-waring\\\\\\\\\\": \\\\\\\\\\"this is {type} warining\\\\\\\\\\"\\\\\\\\n }\\\\\\\\n ]\\\\\\\\n }\\\\\\\\n}\\\\\\\\n\\"')
delete _Component._Ctor

}
"
Expand Down Expand Up @@ -612,8 +616,9 @@ Object {

exports[`useClassComponent: code 1`] = `
"export default function (Component) {
Component.__o.__i18n = Component.__o.__i18n || []
Component.__o.__i18n.push({
const _Component = Component.__o || Component
_Component.__i18n = _Component.__i18n || []
_Component.__i18n.push({
\\"locale\\": \\"\\",
\\"resource\\": {
\\"hi\\": (()=>{const fn=(ctx) => {const { normalize: _normalize } = ctx;return _normalize([\\"hi there!\\"])};fn.source=\\"hi there!\\";return fn;})(),
Expand Down
Expand Up @@ -2,8 +2,9 @@

exports[`array basic: code 1`] = `
"export default function (Component) {
Component.__i18n = Component.__i18n || []
Component.__i18n.push({
const _Component = Component
_Component.__i18n = _Component.__i18n || []
_Component.__i18n.push({
\\"locale\\": \\"\\",
\\"resource\\": {
\\"foo\\": [
Expand Down Expand Up @@ -44,8 +45,9 @@ Object {

exports[`array mixed: code 1`] = `
"export default function (Component) {
Component.__i18n = Component.__i18n || []
Component.__i18n.push({
const _Component = Component
_Component.__i18n = _Component.__i18n || []
_Component.__i18n.push({
\\"locale\\": \\"\\",
\\"resource\\": {
\\"foo\\": [
Expand Down Expand Up @@ -139,8 +141,9 @@ Object {

exports[`bridge with ESM exporting: code 1`] = `
"export default function (Component) {
Component.options.__i18n = Component.options.__i18n || []
Component.options.__i18n.push({
const _Component = Component.options || Component
_Component.__i18n = _Component.__i18n || []
_Component.__i18n.push({
\\"locale\\": \\"\\",
\\"resource\\": {
\\"hi\\": (()=>{const fn=(ctx) => {const { normalize: _normalize } = ctx;return _normalize([\\"hi there!\\"])};fn.source=\\"hi there!\\";return fn;})(),
Expand Down Expand Up @@ -173,8 +176,8 @@ exports[`bridge with ESM exporting: code 1`] = `
}
}
})
Component.options.__i18nBridge = Component.options.__i18nBridge || []
Component.options.__i18nBridge.push('{
_Component.__i18nBridge = _Component.__i18nBridge || []
_Component.__i18nBridge.push('{
\\"hi\\": \\"hi there!\\",
\\"nested\\": {
\\"hello\\": \\"hello world!\\",
Expand All @@ -201,7 +204,7 @@ exports[`bridge with ESM exporting: code 1`] = `
}
}
')
delete Component.options._Ctor
delete _Component._Ctor

}
"
Expand Down Expand Up @@ -273,8 +276,9 @@ Object {

exports[`bridge: code 1`] = `
"module.exports = function (Component) {
Component.options.__i18n = Component.options.__i18n || []
Component.options.__i18n.push({
const _Component = Component.options || Component
_Component.__i18n = _Component.__i18n || []
_Component.__i18n.push({
\\"locale\\": \\"\\",
\\"resource\\": {
\\"hi\\": (()=>{const fn=(ctx) => {const { normalize: _normalize } = ctx;return _normalize([\\"hi there!\\"])};fn.source=\\"hi there!\\";return fn;})(),
Expand Down Expand Up @@ -307,8 +311,8 @@ exports[`bridge: code 1`] = `
}
}
})
Component.options.__i18nBridge = Component.options.__i18nBridge || []
Component.options.__i18nBridge.push('{
_Component.__i18nBridge = _Component.__i18nBridge || []
_Component.__i18nBridge.push('{
\\"hi\\": \\"hi there!\\",
\\"nested\\": {
\\"hello\\": \\"hello world!\\",
Expand All @@ -335,7 +339,7 @@ exports[`bridge: code 1`] = `
}
}
')
delete Component.options._Ctor
delete _Component._Ctor

}
"
Expand Down Expand Up @@ -780,8 +784,9 @@ Object {

exports[`useClassComponent: code 1`] = `
"export default function (Component) {
Component.__o.__i18n = Component.__o.__i18n || []
Component.__o.__i18n.push({
const _Component = Component.__o || Component
_Component.__i18n = _Component.__i18n || []
_Component.__i18n.push({
\\"locale\\": \\"\\",
\\"resource\\": {
\\"hi\\": (()=>{const fn=(ctx) => {const { normalize: _normalize } = ctx;return _normalize([\\"hi there!\\"])};fn.source=\\"hi there!\\";return fn;})(),
Expand Down
Expand Up @@ -2,8 +2,9 @@

exports[`array basic: code 1`] = `
"export default function (Component) {
Component.__i18n = Component.__i18n || []
Component.__i18n.push({
const _Component = Component
_Component.__i18n = _Component.__i18n || []
_Component.__i18n.push({
\\"locale\\": \\"\\",
\\"resource\\": {
\\"foo\\": [
Expand Down Expand Up @@ -43,8 +44,9 @@ Object {

exports[`array mixed: code 1`] = `
"export default function (Component) {
Component.__i18n = Component.__i18n || []
Component.__i18n.push({
const _Component = Component
_Component.__i18n = _Component.__i18n || []
_Component.__i18n.push({
\\"locale\\": \\"\\",
\\"resource\\": {
\\"foo\\": [
Expand Down Expand Up @@ -124,8 +126,9 @@ Object {

exports[`bridge with ESM exporting: code 1`] = `
"export default function (Component) {
Component.options.__i18n = Component.options.__i18n || []
Component.options.__i18n.push({
const _Component = Component.options || Component
_Component.__i18n = _Component.__i18n || []
_Component.__i18n.push({
\\"locale\\": \\"\\",
\\"resource\\": {
\\"hi\\": (()=>{const fn=(ctx) => {const { normalize: _normalize } = ctx;return _normalize([\\"hi there!\\"])};fn.source=\\"hi there!\\";return fn;})(),
Expand Down Expand Up @@ -158,8 +161,8 @@ exports[`bridge with ESM exporting: code 1`] = `
}
}
})
Component.options.__i18nBridge = Component.options.__i18nBridge || []
Component.options.__i18nBridge.push('{
_Component.__i18nBridge = _Component.__i18nBridge || []
_Component.__i18nBridge.push('{
\\"hi\\": \\"hi there!\\",
\\"nested\\": {
\\"hello\\": \\"hello world!\\",
Expand All @@ -186,7 +189,7 @@ exports[`bridge with ESM exporting: code 1`] = `
}
}
')
delete Component.options._Ctor
delete _Component._Ctor

}"
`;
Expand Down Expand Up @@ -251,8 +254,9 @@ complex:

exports[`bridge: code 1`] = `
"module.exports = function (Component) {
Component.options.__i18n = Component.options.__i18n || []
Component.options.__i18n.push({
const _Component = Component.options || Component
_Component.__i18n = _Component.__i18n || []
_Component.__i18n.push({
\\"locale\\": \\"\\",
\\"resource\\": {
\\"hi\\": (()=>{const fn=(ctx) => {const { normalize: _normalize } = ctx;return _normalize([\\"hi there!\\"])};fn.source=\\"hi there!\\";return fn;})(),
Expand Down Expand Up @@ -285,8 +289,8 @@ exports[`bridge: code 1`] = `
}
}
})
Component.options.__i18nBridge = Component.options.__i18nBridge || []
Component.options.__i18nBridge.push('{
_Component.__i18nBridge = _Component.__i18nBridge || []
_Component.__i18nBridge.push('{
\\"hi\\": \\"hi there!\\",
\\"nested\\": {
\\"hello\\": \\"hello world!\\",
Expand All @@ -313,7 +317,7 @@ exports[`bridge: code 1`] = `
}
}
')
delete Component.options._Ctor
delete _Component._Ctor

}"
`;
Expand Down Expand Up @@ -542,8 +546,9 @@ complex:

exports[`useClassComponent: code 1`] = `
"export default function (Component) {
Component.__o.__i18n = Component.__o.__i18n || []
Component.__o.__i18n.push({
const _Component = Component.__o || Component
_Component.__i18n = _Component.__i18n || []
_Component.__i18n.push({
\\"locale\\": \\"\\",
\\"resource\\": {
\\"hi\\": (()=>{const fn=(ctx) => {const { normalize: _normalize } = ctx;return _normalize([\\"hi there!\\"])};fn.source=\\"hi there!\\";return fn;})(),
Expand Down
4 changes: 2 additions & 2 deletions packages/bundle-utils/test/generator/js.test.ts
Expand Up @@ -135,8 +135,8 @@ test('useClassComponent', async () => {

expect(validateSyntax(code)).toBe(true)
expect(code).toMatchSnapshot('code')
expect(code).toContain('Component.__o.__i18n')
expect(code).not.toContain('Component.__i18n')
expect(code).toContain('Component.__o || Component')
expect(code).toContain('_Component.__i18n')
expect(map).toMatchSnapshot('map')
})

Expand Down
5 changes: 3 additions & 2 deletions packages/bundle-utils/test/generator/json.test.ts
Expand Up @@ -137,9 +137,10 @@ test('useClassComponent', async () => {
}
)

expect(validateSyntax(code)).toBe(true)
expect(code).toMatchSnapshot('code')
expect(code).toContain('Component.__o.__i18n')
expect(code).not.toContain('Component.__i18n')
expect(code).toContain('Component.__o || Component')
expect(code).toContain('_Component.__i18n')
expect(map).toMatchSnapshot('map')
})

Expand Down