Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ describe('compiler: expression transform', () => {
[
'pipelineOperator',
{
proposal: 'minimal',
proposal: 'fsharp',
},
],
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1358,20 +1358,6 @@ _sfc_.setup = __setup__
"
`;

exports[`SFC genDefaultAs > parser plugins > import attributes (user override for deprecated syntax) 1`] = `
"import { foo } from './foo.js' assert { type: 'foobar' }

export default {
setup(__props, { expose: __expose }) {
__expose();


return { get foo() { return foo } }
}

}"
`;

exports[`SFC genDefaultAs > parser plugins > import attributes 1`] = `
"import { foo } from './foo.js' with { type: 'foobar' }

Expand Down
16 changes: 0 additions & 16 deletions packages/compiler-sfc/__tests__/compileScript.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1510,22 +1510,6 @@ describe('SFC genDefaultAs', () => {
</script>`),
).toThrow()
})

test('import attributes (user override for deprecated syntax)', () => {
const { content } = compile(
`
<script setup>
import { foo } from './foo.js' assert { type: 'foobar' }
</script>
`,
{
babelParserPlugins: [
['importAttributes', { deprecatedAssertSyntax: true }],
],
},
)
assertCode(content)
})
})
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1653,7 +1653,7 @@ function resolve(
s.expression.type === 'CallExpression' &&
(s.expression.callee as Identifier).name === 'defineProps'
) {
target = s.expression.typeParameters!.params[0]
target = s.expression.typeArguments!.params[0]
}
}
const raw = resolveTypeElements(ctx, target)
Expand Down
5 changes: 1 addition & 4 deletions packages/compiler-sfc/__tests__/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ export function assertCode(code: string): void {
try {
babelParse(code, {
sourceType: 'module',
plugins: [
'typescript',
['importAttributes', { deprecatedAssertSyntax: true }],
],
plugins: ['typescript'],
})
Comment on lines +32 to 33
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

Babel 8 parser config looks correct.

Dropping importAttributes here aligns with the PR direction; TS-only parsing is fine for assertCode().

Run a quick repo scan to ensure no generated code or tests still rely on import attributes (assert/with):


🏁 Script executed:

#!/bin/bash
rg -nP -S 'importAttributes|\\bassert\\s*\\{|\\bwith\\s*\\{' --glob '!node_modules/**'

Length of output: 148


🏁 Script executed:

#!/bin/bash
# Re-run search across all files (including those in .gitignore) to catch any usage of importAttributes, assert {, or with {,
# excluding node_modules and dist directories.
rg -nP --no-ignore-vcs --glob '!node_modules/**' --glob '!dist/**' 'importAttributes|\bassert\s*\{|\bwith\s*\{' 

Length of output: 148


🏁 Script executed:

#!/bin/bash
# Fallback search using grep across TS/JS/Vue files to catch any usage of importAttributes, assert {, or with {,
# excluding node_modules and dist directories.
find . -type f \( -name '*.ts' -o -name '*.js' -o -name '*.vue' \) \
  -not -path './node_modules/*' -not -path './dist/*' \
  -exec grep -nE 'importAttributes|assert\s*\{|with\s*\{' {} +

Length of output: 485


Restore importAttributes support or update tests
Tests in packages/compiler-sfc/tests/compileScript.spec.ts (lines 1501 & 1509) still use

import { foo } from './foo.js' with { type: 'foobar' }
import { foo } from './foo.js' assert { type: 'foobar' }

Dropping the importAttributes parser plugin will break these. Either re-include it for compileSFCScript or remove/adjust those tests.

🤖 Prompt for AI Agents
packages/compiler-sfc/__tests__/utils.ts around lines 32-33: the parser plugins
list removed support for import attributes which breaks tests that use "with {
type: '...'}" / "assert { type: '...'}"; restore the 'importAttributes' parser
plugin in the plugins array passed to compileSFCScript (or to whichever
parse/transform helper is used here) so import attribute syntax is accepted, or
if you prefer to change tests instead, update the tests in
packages/compiler-sfc/__tests__/compileScript.spec.ts to stop using import
attributes; prefer restoring 'importAttributes' in the plugins list to minimally
change behavior and keep existing tests working.

} catch (e: any) {
console.log(code)
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler-sfc/src/compileScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1161,7 +1161,7 @@ function walkDeclaration(
}
}
} else if (node.type === 'TSEnumDeclaration') {
isAllLiteral = node.members.every(
isAllLiteral = node.body.members.every(
member => !member.initializer || isStaticNode(member.initializer),
)
bindings[node.id!.name] = isAllLiteral
Expand Down
15 changes: 2 additions & 13 deletions packages/compiler-sfc/src/script/context.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { CallExpression, Node, ObjectPattern, Program } from '@babel/types'
import type { SFCDescriptor } from '../parse'
import { generateCodeFrame, isArray } from '@vue/shared'
import { generateCodeFrame } from '@vue/shared'
import { type ParserPlugin, parse as babelParse } from '@babel/parser'
import type { ImportBinding, SFCScriptCompileOptions } from '../compileScript'
import type { PropsDestructureBindings } from './defineProps'
Expand Down Expand Up @@ -170,17 +170,6 @@ export function resolveParserPlugins(
dts = false,
): ParserPlugin[] {
const plugins: ParserPlugin[] = []
if (
!userPlugins ||
!userPlugins.some(
p =>
p === 'importAssertions' ||
p === 'importAttributes' ||
(isArray(p) && p[0] === 'importAttributes'),
)
) {
plugins.push('importAttributes')
}
if (lang === 'jsx' || lang === 'tsx' || lang === 'mtsx') {
plugins.push('jsx')
} else if (userPlugins) {
Expand All @@ -189,7 +178,7 @@ export function resolveParserPlugins(
userPlugins = userPlugins.filter(p => p !== 'jsx')
}
if (lang === 'ts' || lang === 'mts' || lang === 'tsx' || lang === 'mtsx') {
plugins.push(['typescript', { dts }], 'explicitResourceManagement')
plugins.push(['typescript', { dts }])
if (!userPlugins || !userPlugins.includes('decorators')) {
plugins.push('decorators-legacy')
}
Expand Down
8 changes: 4 additions & 4 deletions packages/compiler-sfc/src/script/defineEmits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ export function processDefineEmits(
}
ctx.hasDefineEmitCall = true
ctx.emitsRuntimeDecl = node.arguments[0]
if (node.typeParameters) {
if (node.typeArguments) {
if (ctx.emitsRuntimeDecl) {
ctx.error(
`${DEFINE_EMITS}() cannot accept both type and non-type arguments ` +
`at the same time. Use one or the other.`,
node,
)
}
ctx.emitsTypeDecl = node.typeParameters.params[0]
ctx.emitsTypeDecl = node.typeArguments.params[0]
}

ctx.emitDecl = declId
Expand Down Expand Up @@ -75,7 +75,7 @@ export function extractRuntimeEmits(ctx: TypeResolveContext): Set<string> {
const node = ctx.emitsTypeDecl!

if (node.type === 'TSFunctionType') {
extractEventNames(ctx, node.parameters[0], emits)
extractEventNames(ctx, node.params[0], emits)
return emits
}

Expand All @@ -95,7 +95,7 @@ export function extractRuntimeEmits(ctx: TypeResolveContext): Set<string> {
)
}
for (const call of calls) {
extractEventNames(ctx, call.parameters[0], emits)
extractEventNames(ctx, call.params[0], emits)
}
}

Expand Down
5 changes: 3 additions & 2 deletions packages/compiler-sfc/src/script/defineModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ export function processDefineModel(

ctx.hasDefineModelCall = true

const type =
(node.typeParameters && node.typeParameters.params[0]) || undefined
const type = (node.typeArguments && node.typeArguments.params[0]) as
| TSType
| undefined
let modelName: string
let options: Node | undefined
const arg0 = node.arguments[0] && unwrapTSNode(node.arguments[0])
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler-sfc/src/script/defineOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function processDefineOptions(
if (ctx.hasDefineOptionsCall) {
ctx.error(`duplicate ${DEFINE_OPTIONS}() call`, node)
}
if (node.typeParameters) {
if (node.typeArguments) {
ctx.error(`${DEFINE_OPTIONS}() cannot accept type arguments`, node)
}
if (!node.arguments[0]) return true
Expand Down
4 changes: 2 additions & 2 deletions packages/compiler-sfc/src/script/defineProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ export function processDefineProps(
}

// call has type parameters - infer runtime types from it
if (node.typeParameters) {
if (node.typeArguments) {
if (ctx.propsRuntimeDecl) {
ctx.error(
`${DEFINE_PROPS}() cannot accept both type and non-type arguments ` +
`at the same time. Use one or the other.`,
node,
)
}
ctx.propsTypeDecl = node.typeParameters.params[0]
ctx.propsTypeDecl = node.typeArguments.params[0]
}

// handle props destructure
Expand Down
Loading