Skip to content

Commit ae42ce3

Browse files
authored
Fix wrong tokenize for lone ampersand (#158)
1 parent 806a38c commit ae42ce3

File tree

8 files changed

+2033
-15
lines changed

8 files changed

+2033
-15
lines changed

Diff for: .github/workflows/CI.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ jobs:
9191
- name: Build
9292
run: npm run -s build
9393
- name: Test
94-
run: npm run -s test:mocha
94+
run: npm run -s test:cover
9595
- name: Send Coverage
9696
run: npm run -s codecov
9797
env:

Diff for: package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@
7272
"setup": "git submodule update --init && cd test/fixtures/eslint && npm install",
7373
"pretest": "run-s build lint",
7474
"test": "npm run -s test:mocha",
75-
"test:mocha": "nyc mocha \"test/*.js\" --reporter dot --timeout 60000",
75+
"test:mocha": "mocha --require ts-node/register \"test/*.js\" --reporter dot --timeout 60000",
76+
"test:cover": "nyc mocha \"test/*.js\" --reporter dot --timeout 60000",
7677
"test:debug": "mocha --require ts-node/register/transpile-only \"test/*.js\" --reporter dot --timeout 60000",
7778
"preupdate-fixtures": "npm run -s build",
7879
"update-fixtures": "node scripts/update-fixtures-ast.js && node scripts/update-fixtures-document-fragment.js",

Diff for: src/html/tokenizer.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1610,14 +1610,14 @@ export class Tokenizer {
16101610
this.crStartOffset = this.offset - 1
16111611
this.buffer = [AMPERSAND]
16121612

1613-
if (isWhitespace(cp) || cp === LESS_THAN_SIGN || cp === EOF) {
1614-
return this.reconsumeAs("CHARACTER_REFERENCE_END")
1613+
if (isDigit(cp) || isLetter(cp)) {
1614+
return this.reconsumeAs("NAMED_CHARACTER_REFERENCE")
16151615
}
16161616
if (cp === NUMBER_SIGN) {
16171617
this.buffer.push(cp)
16181618
return "NUMERIC_CHARACTER_REFERENCE"
16191619
}
1620-
return this.reconsumeAs("NAMED_CHARACTER_REFERENCE")
1620+
return this.reconsumeAs("CHARACTER_REFERENCE_END")
16211621
}
16221622

16231623
/**
@@ -1818,7 +1818,7 @@ export class Tokenizer {
18181818
}
18191819

18201820
/**
1821-
* https://html.spec.whatwg.org/multipage/parsing.html#character-reference-end-state
1821+
* https://html.spec.whatwg.org/multipage/parsing.html#flush-code-points-consumed-as-a-character-reference
18221822
* @param cp The current code point.
18231823
* @returns The next state.
18241824
*/

Diff for: test/espree.js

+21-9
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,13 @@ function parentMain() {
1010

1111
describe("Loading espree from ESLint", () => {
1212
it("should load espree from the ESLint location.", (done) => {
13-
spawn(process.execPath, [__filename, "--child1"], {
14-
stdio: "inherit",
15-
})
13+
spawn(
14+
process.execPath,
15+
["--require", "ts-node/register", __filename, "--child1"],
16+
{
17+
stdio: "inherit",
18+
},
19+
)
1620
.on("error", done)
1721
.on("exit", (code) =>
1822
code
@@ -21,9 +25,13 @@ function parentMain() {
2125
)
2226
})
2327
it("should load espree from the ESLint location.", (done) => {
24-
spawn(process.execPath, [__filename, "--child1"], {
25-
stdio: "inherit",
26-
})
28+
spawn(
29+
process.execPath,
30+
["--require", "ts-node/register", __filename, "--child1"],
31+
{
32+
stdio: "inherit",
33+
},
34+
)
2735
.on("error", done)
2836
.on("exit", (code) =>
2937
code
@@ -38,9 +46,13 @@ function parentMain() {
3846
execSync("npm i", {
3947
stdio: "inherit",
4048
})
41-
spawn(process.execPath, [__filename, "--child2"], {
42-
stdio: "inherit",
43-
})
49+
spawn(
50+
process.execPath,
51+
["--require", "ts-node/register", __filename, "--child2"],
52+
{
53+
stdio: "inherit",
54+
},
55+
)
4456
.on("error", done)
4557
.on("exit", (code) =>
4658
code

0 commit comments

Comments
 (0)