Skip to content

Commit b160a65

Browse files
authored
feat: support script setup context (#216)
* feat: support script setup * feat: support script setup context
1 parent b56ef33 commit b160a65

File tree

6 files changed

+2759
-9701
lines changed

6 files changed

+2759
-9701
lines changed

eslint.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export default [
5050
}
5151
},
5252
rules: {
53+
'@typescript-eslint/ban-ts-comment': 'off',
5354
'@typescript-eslint/no-unused-vars': [
5455
'error',
5556
{

src/transform.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ import {
22
createSimpleExpression,
33
NodeTypes,
44
isText,
5+
BindingTypes,
56
createCompoundExpression,
67
TO_DISPLAY_STRING
78
} from '@vue/compiler-dom'
8-
import { isNumber, isObject, isString, isSymbol, toDisplayString } from '@intlify/shared'
9+
import { isNumber, isObject, isString, isSymbol, toDisplayString, hasOwn } from '@intlify/shared'
910
import { evaluateValue, parseVTExpression } from './transpiler'
1011
import { report, ReportCodes } from './report'
1112
import { createContentBuilder } from './builder'
@@ -367,7 +368,16 @@ function generateTranslationCode(
367368
}
368369

369370
function generateComposableCode(context: TransformContext, params: TranslationParams): string {
370-
const baseCode = `${context.prefixIdentifiers ? '_ctx.' : ''}t`
371+
const { prefixIdentifiers, bindingMetadata } = context
372+
const functionName = 't'
373+
const type = hasOwn(bindingMetadata, functionName) && bindingMetadata[functionName]
374+
// prettier-ignore
375+
const prefixContext = prefixIdentifiers
376+
? type && type.startsWith('setup') || type === BindingTypes.LITERAL_CONST
377+
? '$setup.'
378+
: '_ctx.'
379+
: ''
380+
const baseCode = `${prefixContext}${functionName}`
371381

372382
const builder = createContentBuilder()
373383
builder.push(`${baseCode}(`)

0 commit comments

Comments
 (0)