Skip to content

Commit

Permalink
breaking(bundle-utils): drop useClassComponent option (#367)
Browse files Browse the repository at this point in the history
* breaking(bundle-utils): drop unneccesary `vueVersion` option

* breaking(bundle-utils): drop `useClassComponent` option

* fix
  • Loading branch information
kazupon committed May 16, 2024
1 parent cebdc1c commit 68f63aa
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 390 deletions.
1 change: 0 additions & 1 deletion packages/bundle-utils/src/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ export interface CodeGenOptions {
locale?: string
env?: DevEnv
forceStringify?: boolean
useClassComponent?: boolean
allowDynamic?: boolean
strictMessage?: boolean
escapeHtml?: boolean
Expand Down
14 changes: 5 additions & 9 deletions packages/bundle-utils/src/js.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ export function generate(
onError = undefined,
strictMessage = true,
escapeHtml = false,
useClassComponent = false,
allowDynamic = false,
jit = false
}: CodeGenOptions
Expand All @@ -62,7 +61,6 @@ export function generate(
onError,
strictMessage,
escapeHtml,
useClassComponent,
jit
} as CodeGenOptions
const generator = createCodeGenerator(options)
Expand Down Expand Up @@ -158,7 +156,7 @@ function _generate(
const skipStack = [] as boolean[]
const { forceStringify } = generator.context()
const codeMaps = new Map<string, RawSourceMap>()
const { type, sourceMap, isGlobal, locale, useClassComponent, jit } = options
const { type, sourceMap, isGlobal, locale, jit } = options

const codegenFn: CodeGenFunction = jit
? generateResourceAst
Expand Down Expand Up @@ -188,12 +186,10 @@ function _generate(
const exportSyntax = 'export default'
generator.push(`${exportSyntax} function (Component) {`)
generator.indent()
// prettier-ignore
const componentVariable = useClassComponent
? `Component.__o || Component.__vccOpts || Component`
: `Component`
// prettier-ignore
generator.pushline(`const ${componentNamespace} = ${componentVariable}`)
const componentVariable = `Component`
generator.pushline(
`const ${componentNamespace} = ${componentVariable}`
)
generator.pushline(
`${componentNamespace}.${variableName} = ${componentNamespace}.${variableName} || []`
)
Expand Down
14 changes: 5 additions & 9 deletions packages/bundle-utils/src/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export function generate(
onError = undefined,
strictMessage = true,
escapeHtml = false,
useClassComponent = false,
jit = false
}: CodeGenOptions
): CodeGenResult<JSONProgram> {
Expand All @@ -64,7 +63,6 @@ export function generate(
onError,
strictMessage,
escapeHtml,
useClassComponent,
jit
} as CodeGenOptions
const generator = createCodeGenerator(options)
Expand Down Expand Up @@ -114,7 +112,7 @@ function _generate(
const itemsCountStack = [] as number[]
const { forceStringify } = generator.context()
const codeMaps = new Map<string, RawSourceMap>()
const { type, sourceMap, isGlobal, locale, useClassComponent, jit } = options
const { type, sourceMap, isGlobal, locale, jit } = options

const codegenFn: CodeGenFunction = jit
? generateResourceAst
Expand All @@ -137,12 +135,10 @@ function _generate(
const exportSyntax = 'export default'
generator.push(`${exportSyntax} function (Component) {`)
generator.indent()
// prettier-ignore
const componentVariable = useClassComponent
? `Component.__o || Component.__vccOpts || Component`
: `Component`
// prettier-ignore
generator.pushline(`const ${componentNamespace} = ${componentVariable}`)
const componentVariable = `Component`
generator.pushline(
`const ${componentNamespace} = ${componentVariable}`
)
generator.pushline(
`${componentNamespace}.${variableName} = ${componentNamespace}.${variableName} || []`
)
Expand Down
14 changes: 5 additions & 9 deletions packages/bundle-utils/src/yaml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ export function generate(
{
type = 'plain',
onlyLocales = [],
useClassComponent = false,
filename = 'vue-i18n-loader.yaml',
inSourceMap = undefined,
locale = '',
Expand Down Expand Up @@ -64,7 +63,6 @@ export function generate(
onError,
strictMessage,
escapeHtml,
useClassComponent,
jit
} as CodeGenOptions
const generator = createCodeGenerator(options)
Expand Down Expand Up @@ -107,7 +105,7 @@ function _generate(
const itemsCountStack = [] as number[]
const { forceStringify } = generator.context()
const codeMaps = new Map<string, RawSourceMap>()
const { type, sourceMap, isGlobal, locale, useClassComponent, jit } = options
const { type, sourceMap, isGlobal, locale, jit } = options

const codegenFn: CodeGenFunction = jit
? generateResourceAst
Expand All @@ -129,12 +127,10 @@ function _generate(
const exportSyntax = 'export default'
generator.push(`${exportSyntax} function (Component) {`)
generator.indent()
// prettier-ignore
const componentVariable = useClassComponent
? `Component.__o || Component.__vccOpts || Component`
: `Component`
// prettier-ignore
generator.pushline(`const ${componentNamespace} = ${componentVariable}`)
const componentVariable = `Component`
generator.pushline(
`const ${componentNamespace} = ${componentVariable}`
)
generator.pushline(
`${componentNamespace}.${variableName} = ${componentNamespace}.${variableName} || []`
)
Expand Down
51 changes: 0 additions & 51 deletions packages/bundle-utils/test/generator/__snapshots__/js.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -574,54 +574,3 @@ exports[`unhandling > map 1`] = `
"version": 3,
}
`;
exports[`useClassComponent > code 1`] = `
"export default function (Component) {
const _Component = Component.__o || Component.__vccOpts || 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;})(),
\\"nested\\": {
\\"hello\\": (()=>{const fn=(ctx) => {const { normalize: _normalize } = ctx;return _normalize([\\"hello world!\\"])};fn.source=\\"hello world!\\";return fn;})(),
\\"more\\": {
\\"plural\\": (()=>{const fn=(ctx) => {const { normalize: _normalize, linked: _linked, type: _type, interpolate: _interpolate, list: _list, named: _named, plural: _plural } = ctx;return _plural([_normalize([_linked(\\"no apples\\", \\"caml\\", _type)]), _normalize([_interpolate(_list(0)), \\" apple\\"]), _normalize([_interpolate(_named(\\"n\\")), \\" apples\\"])])};fn.source=\\"@.caml:{'no apples'} | {0} apple | {n} apples\\";return fn;})()
},
\\"list\\": (()=>{const fn=(ctx) => {const { normalize: _normalize, interpolate: _interpolate, list: _list } = ctx;return _normalize([\\"hi, \\", _interpolate(_list(0)), \\" !\\"])};fn.source=\\"hi, {0} !\\";return fn;})()
},
\\"template\\": (()=>{const fn=(ctx) => {const { normalize: _normalize } = ctx;return _normalize([\\"hello world!\\"])};fn.source=\\"hello world!\\";return fn;})(),
\\"こんにちは\\": (()=>{const fn=(ctx) => {const { normalize: _normalize } = ctx;return _normalize([\\"こんにちは!\\"])};fn.source=\\"こんにちは!\\";return fn;})(),
\\"single-quote\\": (()=>{const fn=(ctx) => {const { normalize: _normalize } = ctx;return _normalize([\\"I don't know!\\"])};fn.source=\\"I don't know!\\";return fn;})(),
\\"emoji\\": (()=>{const fn=(ctx) => {const { normalize: _normalize } = ctx;return _normalize([\\"😺\\"])};fn.source=\\"😺\\";return fn;})(),
\\"unicode\\": (()=>{const fn=(ctx) => {const { normalize: _normalize } = ctx;return _normalize([\\"A\\"])};fn.source=\\"A\\";return fn;})(),
\\"unicode-escape\\": (()=>{const fn=(ctx) => {const { normalize: _normalize } = ctx;return _normalize([\\"\\\\\\\\u0041\\"])};fn.source=\\"\\\\\\\\u0041\\";return fn;})(),
\\"backslash-single-quote\\": (()=>{const fn=(ctx) => {const { normalize: _normalize } = ctx;return _normalize([\\"\\\\\\\\'\\"])};fn.source=\\"\\\\\\\\'\\";return fn;})(),
\\"backslash-backslash\\": (()=>{const fn=(ctx) => {const { normalize: _normalize } = ctx;return _normalize([\\"\\\\\\\\\\\\\\\\\\"])};fn.source=\\"\\\\\\\\\\\\\\\\\\";return fn;})(),
\\"errors\\": [
(()=>{const fn=(ctx) => {const { normalize: _normalize } = ctx;return _normalize([\\"ERROR1001\\"])};fn.source=\\"ERROR1001\\";return fn;})(),
(()=>{const fn=(ctx) => {const { normalize: _normalize } = ctx;return _normalize([\\"ERROR1002\\"])};fn.source=\\"ERROR1002\\";return fn;})(),
],
\\"complex\\": {
\\"warnings\\": [
(()=>{const fn=(ctx) => {const { normalize: _normalize } = ctx;return _normalize([\\"NOTE: This is warning\\"])};fn.source=\\"NOTE: This is warning\\";return fn;})(),
{
\\"named-waring\\": (()=>{const fn=(ctx) => {const { normalize: _normalize, interpolate: _interpolate, named: _named } = ctx;return _normalize([\\"this is \\", _interpolate(_named(\\"type\\")), \\" warining\\"])};fn.source=\\"this is {type} warining\\";return fn;})()
}
]
}
}
})
}
"
`;
exports[`useClassComponent > map 1`] = `
{
"mappings": "",
"names": [],
"sources": [],
"version": 3,
}
`;

0 comments on commit 68f63aa

Please sign in to comment.