Skip to content

Fix wrong tokenize for lone ampersand #158

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 23, 2022
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ jobs:
- name: Build
run: npm run -s build
- name: Test
run: npm run -s test:mocha
run: npm run -s test:cover
- name: Send Coverage
run: npm run -s codecov
env:
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@
"setup": "git submodule update --init && cd test/fixtures/eslint && npm install",
"pretest": "run-s build lint",
"test": "npm run -s test:mocha",
"test:mocha": "nyc mocha \"test/*.js\" --reporter dot --timeout 60000",
"test:mocha": "mocha --require ts-node/register \"test/*.js\" --reporter dot --timeout 60000",
"test:cover": "nyc mocha \"test/*.js\" --reporter dot --timeout 60000",
"test:debug": "mocha --require ts-node/register/transpile-only \"test/*.js\" --reporter dot --timeout 60000",
"preupdate-fixtures": "npm run -s build",
"update-fixtures": "node scripts/update-fixtures-ast.js && node scripts/update-fixtures-document-fragment.js",
Expand Down
8 changes: 4 additions & 4 deletions src/html/tokenizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1610,14 +1610,14 @@ export class Tokenizer {
this.crStartOffset = this.offset - 1
this.buffer = [AMPERSAND]

if (isWhitespace(cp) || cp === LESS_THAN_SIGN || cp === EOF) {
return this.reconsumeAs("CHARACTER_REFERENCE_END")
if (isDigit(cp) || isLetter(cp)) {
return this.reconsumeAs("NAMED_CHARACTER_REFERENCE")
}
if (cp === NUMBER_SIGN) {
this.buffer.push(cp)
return "NUMERIC_CHARACTER_REFERENCE"
}
return this.reconsumeAs("NAMED_CHARACTER_REFERENCE")
return this.reconsumeAs("CHARACTER_REFERENCE_END")
}

/**
Expand Down Expand Up @@ -1818,7 +1818,7 @@ export class Tokenizer {
}

/**
* https://html.spec.whatwg.org/multipage/parsing.html#character-reference-end-state
* https://html.spec.whatwg.org/multipage/parsing.html#flush-code-points-consumed-as-a-character-reference
* @param cp The current code point.
* @returns The next state.
*/
Expand Down
30 changes: 21 additions & 9 deletions test/espree.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@ function parentMain() {

describe("Loading espree from ESLint", () => {
it("should load espree from the ESLint location.", (done) => {
spawn(process.execPath, [__filename, "--child1"], {
stdio: "inherit",
})
spawn(
process.execPath,
["--require", "ts-node/register", __filename, "--child1"],
{
stdio: "inherit",
},
)
.on("error", done)
.on("exit", (code) =>
code
Expand All @@ -21,9 +25,13 @@ function parentMain() {
)
})
it("should load espree from the ESLint location.", (done) => {
spawn(process.execPath, [__filename, "--child1"], {
stdio: "inherit",
})
spawn(
process.execPath,
["--require", "ts-node/register", __filename, "--child1"],
{
stdio: "inherit",
},
)
.on("error", done)
.on("exit", (code) =>
code
Expand All @@ -38,9 +46,13 @@ function parentMain() {
execSync("npm i", {
stdio: "inherit",
})
spawn(process.execPath, [__filename, "--child2"], {
stdio: "inherit",
})
spawn(
process.execPath,
["--require", "ts-node/register", __filename, "--child2"],
{
stdio: "inherit",
},
)
.on("error", done)
.on("exit", (code) =>
code
Expand Down
Loading