Skip to content

Custom template tokenizers #148

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 18 commits into from
Apr 14, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
don't have empty tokens in custom tokenizer
  • Loading branch information
rashfael committed Mar 31, 2022
commit ac34a9ded850fbde59786148003b679287c604de
18 changes: 0 additions & 18 deletions test/fixtures/ast/custom-template-tokenizer/ast.json
Original file line number Diff line number Diff line change
Expand Up @@ -797,24 +797,6 @@
"value": "}}",
"type": "VExpressionEnd"
},
{
"range": [
82,
82
],
"loc": {
"start": {
"line": 2,
"column": 53
},
"end": {
"line": 2,
"column": 53
}
},
"value": "",
"type": "CustomEndTag"
},
{
"type": "HTMLEndTagOpen",
"range": [
Expand Down
40 changes: 20 additions & 20 deletions test/fixtures/ast/custom-template-tokenizer/custom-tokenizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module.exports = class CustomTokenizer {
this.line = startingLine
this.column = startingColumn
this.offset = 28
this.tokens = [
const tokens = [
this.generateToken("\n ", {
type: "CustomWhitespace"
}),
Expand Down Expand Up @@ -53,8 +53,8 @@ module.exports = class CustomTokenizer {
value: "comment"
})
]
this.comments = this.tokens.filter(token => token.type === "CustomComment")
this.tokens = this.tokens.filter(token => token.type !== "CustomComment")
this.comments = tokens.filter(token => token.type === "CustomComment")
this.tokens = tokens.filter(token => !["CustomEndTag", "CustomComment"].includes(token.type))

this.errors = [{
"message": "totally-made-up-error",
Expand All @@ -67,10 +67,10 @@ module.exports = class CustomTokenizer {
type: "VAttribute",
parent: {},
directive: false,
range: [this.tokens[2].range[0], this.tokens[4].range[1]],
range: [tokens[2].range[0], tokens[4].range[1]],
loc: {
start: this.tokens[2].start,
end: this.tokens[4].end
start: tokens[2].start,
end: tokens[4].end
}
}

Expand All @@ -79,45 +79,45 @@ module.exports = class CustomTokenizer {
parent: attribute,
name: ":made",
rawName: ":made",
range: this.tokens[2].range,
loc: this.tokens[2].loc
range: tokens[2].range,
loc: tokens[2].loc
}

attribute.value = {
type: "VLiteral",
parent: attribute,
value: "up",
range: this.tokens[4].range,
loc: this.tokens[4].loc
range: tokens[4].range,
loc: tokens[4].loc
}

// these tokens get returned by nextToken
const intermediateTokens = [{
type: "StartTag",
name: "a-totally",
rawName: "A-totally",
range: [this.tokens[1].range[0], this.tokens[5].range[1]],
range: [tokens[1].range[0], tokens[5].range[1]],
loc: {
start: this.tokens[1].loc.start,
end: this.tokens[5].loc.end
start: tokens[1].loc.start,
end: tokens[5].loc.end
},
selfClosing: false,
attributes: [attribute]
}, {
type: "Mustache",
value: " templating + language ",
range: [this.tokens[6].range[0], this.tokens[8].range[1]],
range: [tokens[6].range[0], tokens[8].range[1]],
loc: {
start: this.tokens[6].loc.start,
end: this.tokens[8].loc.end
start: tokens[6].loc.start,
end: tokens[8].loc.end
},
startToken: this.tokens[6],
endToken: this.tokens[8]
startToken: tokens[6],
endToken: tokens[8]
}, {
type: "EndTag",
name: "a-totally",
range: this.tokens[9].range,
loc: this.tokens[9].loc,
range: tokens[9].range,
loc: tokens[9].loc,
}]
this.tokenIterator = intermediateTokens[Symbol.iterator]()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"+",
"language",
"}}",
"",
"</template",
">",
"\n",
Expand Down