Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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
293 changes: 253 additions & 40 deletions packages/compiler-core/__tests__/__snapshots__/parse.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2444,6 +2444,113 @@ exports[`compiler: parse > Errors > MISSING_END_TAG_NAME > <template></></templa
}
`;

exports[`compiler: parse > Errors > UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME > <template><div "></div></template> 1`] = `
{
"cached": [],
"children": [
{
"children": [
{
"children": [],
"codegenNode": undefined,
"loc": {
"end": {
"column": 24,
"line": 1,
"offset": 23,
},
"source": "<div "></div>",
"start": {
"column": 11,
"line": 1,
"offset": 10,
},
},
"ns": 0,
"props": [
{
"loc": {
"end": {
"column": 17,
"line": 1,
"offset": 16,
},
"source": """,
"start": {
"column": 16,
"line": 1,
"offset": 15,
},
},
"name": """,
"nameLoc": {
"end": {
"column": 17,
"line": 1,
"offset": 16,
},
"source": """,
"start": {
"column": 16,
"line": 1,
"offset": 15,
},
},
"type": 6,
"value": undefined,
},
],
"tag": "div",
"tagType": 0,
"type": 1,
},
],
"codegenNode": undefined,
"loc": {
"end": {
"column": 35,
"line": 1,
"offset": 34,
},
"source": "<template><div "></div></template>",
"start": {
"column": 1,
"line": 1,
"offset": 0,
},
},
"ns": 0,
"props": [],
"tag": "template",
"tagType": 0,
"type": 1,
},
],
"codegenNode": undefined,
"components": [],
"directives": [],
"helpers": Set {},
"hoists": [],
"imports": [],
"loc": {
"end": {
"column": 35,
"line": 1,
"offset": 34,
},
"source": "<template><div "></div></template>",
"start": {
"column": 1,
"line": 1,
"offset": 0,
},
},
"source": "<template><div "></div></template>",
"temps": 0,
"type": 0,
}
`;

exports[`compiler: parse > Errors > UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME > <template><div a"bc=''></div></template> 1`] = `
{
"cached": [],
Expand Down Expand Up @@ -2813,6 +2920,144 @@ exports[`compiler: parse > Errors > UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME > <te
}
`;

exports[`compiler: parse > Errors > UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME > <template><div foo "></div></template> 1`] = `
{
"cached": [],
"children": [
{
"children": [
{
"children": [],
"codegenNode": undefined,
"loc": {
"end": {
"column": 28,
"line": 1,
"offset": 27,
},
"source": "<div foo "></div>",
"start": {
"column": 11,
"line": 1,
"offset": 10,
},
},
"ns": 0,
"props": [
{
"loc": {
"end": {
"column": 19,
"line": 1,
"offset": 18,
},
"source": "foo",
"start": {
"column": 16,
"line": 1,
"offset": 15,
},
},
"name": "foo",
"nameLoc": {
"end": {
"column": 19,
"line": 1,
"offset": 18,
},
"source": "foo",
"start": {
"column": 16,
"line": 1,
"offset": 15,
},
},
"type": 6,
"value": undefined,
},
{
"loc": {
"end": {
"column": 21,
"line": 1,
"offset": 20,
},
"source": """,
"start": {
"column": 20,
"line": 1,
"offset": 19,
},
},
"name": """,
"nameLoc": {
"end": {
"column": 21,
"line": 1,
"offset": 20,
},
"source": """,
"start": {
"column": 20,
"line": 1,
"offset": 19,
},
},
"type": 6,
"value": undefined,
},
],
"tag": "div",
"tagType": 0,
"type": 1,
},
],
"codegenNode": undefined,
"loc": {
"end": {
"column": 39,
"line": 1,
"offset": 38,
},
"source": "<template><div foo "></div></template>",
"start": {
"column": 1,
"line": 1,
"offset": 0,
},
},
"ns": 0,
"props": [],
"tag": "template",
"tagType": 0,
"type": 1,
},
],
"codegenNode": undefined,
"components": [],
"directives": [],
"helpers": Set {},
"hoists": [],
"imports": [],
"loc": {
"end": {
"column": 39,
"line": 1,
"offset": 38,
},
"source": "<template><div foo "></div></template>",
"start": {
"column": 1,
"line": 1,
"offset": 0,
},
},
"source": "<template><div foo "></div></template>",
"temps": 0,
"type": 0,
}
`;

exports[`compiler: parse > Errors > UNEXPECTED_CHARACTER_IN_UNQUOTED_ATTRIBUTE_VALUE > <template><div foo=bar"></div></template> 1`] = `
{
"cached": [],
Expand Down Expand Up @@ -3451,39 +3696,7 @@ exports[`compiler: parse > Errors > UNEXPECTED_EQUALS_SIGN_BEFORE_ATTRIBUTE_NAME
},
},
"ns": 0,
"props": [
{
"loc": {
"end": {
"column": 17,
"line": 1,
"offset": 16,
},
"source": "=",
"start": {
"column": 16,
"line": 1,
"offset": 15,
},
},
"name": "=",
"nameLoc": {
"end": {
"column": 17,
"line": 1,
"offset": 16,
},
"source": "=",
"start": {
"column": 16,
"line": 1,
"offset": 15,
},
},
"type": 6,
"value": undefined,
},
],
"props": [],
"tag": "div",
"tagType": 0,
"type": 1,
Expand Down Expand Up @@ -3566,25 +3779,25 @@ exports[`compiler: parse > Errors > UNEXPECTED_EQUALS_SIGN_BEFORE_ATTRIBUTE_NAME
"line": 1,
"offset": 23,
},
"source": "=foo=bar",
"source": "foo=bar",
"start": {
"column": 16,
"column": 17,
"line": 1,
"offset": 15,
"offset": 16,
},
},
"name": "=foo",
"name": "foo",
"nameLoc": {
"end": {
"column": 20,
"line": 1,
"offset": 19,
},
"source": "=foo",
"source": "foo",
"start": {
"column": 16,
"column": 17,
"line": 1,
"offset": 15,
"offset": 16,
},
},
"type": 6,
Expand Down
18 changes: 18 additions & 0 deletions packages/compiler-core/__tests__/parse.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3210,6 +3210,24 @@ describe('compiler: parse', () => {
},
],
},
{
code: '<template><div "></div></template>',
errors: [
{
type: ErrorCodes.UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME,
loc: { offset: 15, line: 1, column: 16 },
},
],
},
{
code: '<template><div foo "></div></template>',
errors: [
{
type: ErrorCodes.UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME,
loc: { offset: 19, line: 1, column: 20 },
},
],
},
],
UNEXPECTED_CHARACTER_IN_UNQUOTED_ATTRIBUTE_VALUE: [
{
Expand Down
14 changes: 7 additions & 7 deletions packages/compiler-core/src/tokenizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -651,17 +651,16 @@ export default class Tokenizer {
this.state = State.BeforeTagName
this.sectionStart = this.index
} else if (!isWhitespace(c)) {
if ((__DEV__ || !__BROWSER__) && c === CharCodes.Eq) {
this.cbs.onerr(
ErrorCodes.UNEXPECTED_EQUALS_SIGN_BEFORE_ATTRIBUTE_NAME,
this.index,
)
}
this.handleAttrStart(c)
}
}
private handleAttrStart(c: number) {
if (c === CharCodes.LowerV && this.peek() === CharCodes.Dash) {
if ((__DEV__ || !__BROWSER__) && c === CharCodes.Eq) {
this.cbs.onerr(
ErrorCodes.UNEXPECTED_EQUALS_SIGN_BEFORE_ATTRIBUTE_NAME,
this.index,
)
} else if (c === CharCodes.LowerV && this.peek() === CharCodes.Dash) {
this.state = State.InDirName
this.sectionStart = this.index
} else if (
Expand All @@ -676,6 +675,7 @@ export default class Tokenizer {
} else {
this.state = State.InAttrName
this.sectionStart = this.index
this.stateInAttrName(c)
}
}
private stateInSelfClosingTag(c: number): void {
Expand Down
Loading