Skip to content

Commit

Permalink
rename token type and methods
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Nov 19, 2021
1 parent afce535 commit 491c921
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion eslint/babel-eslint-parser/src/convert/convertTokens.cjs
Expand Up @@ -179,7 +179,7 @@ function convertToken(token, source, tl) {
token.value = `${token.value}n`;
} else if (label === tl.privateName) {
token.type = "PrivateIdentifier";
} else if (label === tl.templateMiddle || label === tl.templateTail) {
} else if (label === tl.templateNonTail || label === tl.templateTail) {
token.type = "Template";
}

Expand Down
8 changes: 4 additions & 4 deletions packages/babel-parser/src/parser/expression.js
Expand Up @@ -708,7 +708,7 @@ export default class ExpressionParser extends LValParser {
): N.Expression {
if (!noCalls && this.eat(tt.doubleColon)) {
return this.parseBind(base, startPos, startLoc, noCalls, state);
} else if (this.match(tt.templateMiddle) || this.match(tt.templateTail)) {
} else if (this.match(tt.templateNonTail) || this.match(tt.templateTail)) {
return this.parseTaggedTemplateExpression(
base,
startPos,
Expand Down Expand Up @@ -1153,7 +1153,7 @@ export default class ExpressionParser extends LValParser {
case tt._new:
return this.parseNewOrNewTarget();

case tt.templateMiddle:
case tt.templateNonTail:
case tt.templateTail:
return this.parseTemplate(false);

Expand Down Expand Up @@ -1870,7 +1870,7 @@ export default class ExpressionParser extends LValParser {
node.quasis = [curElt];
while (!curElt.tail) {
node.expressions.push(this.parseTemplateSubstitution());
this.readTemplateMiddle();
this.readTemplateContinuation();
node.quasis.push((curElt = this.parseTemplateElement(isTagged)));
}
return this.finishNode(node, "TemplateLiteral");
Expand Down Expand Up @@ -2698,7 +2698,7 @@ export default class ExpressionParser extends LValParser {
this.match(tt.plusMin) ||
this.match(tt.parenL) ||
this.match(tt.bracketL) ||
this.match(tt.templateMiddle) ||
this.match(tt.templateNonTail) ||
this.match(tt.templateTail) ||
// Sometimes the tokenizer generates tt.slash for regexps, and this is
// handler by parseExprAtom
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-parser/src/parser/statement.js
Expand Up @@ -96,7 +96,7 @@ function babel7CompatTokens(tokens) {
continue;
}
}
if (type === tt.templateMiddle || type === tt.templateTail) {
if (type === tt.templateNonTail || type === tt.templateTail) {
if (!process.env.BABEL_8_BREAKING) {
const { loc, start, value, end } = token;
const backquoteEnd = start + 1;
Expand Down
4 changes: 2 additions & 2 deletions packages/babel-parser/src/plugins/typescript/index.js
Expand Up @@ -1071,7 +1071,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
}

return this.tsParseParenthesizedType();
case tt.templateMiddle:
case tt.templateNonTail:
case tt.templateTail:
return this.tsParseTemplateLiteralType();
default: {
Expand Down Expand Up @@ -2198,7 +2198,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>

return this.finishCallExpression(node, state.optionalChainMember);
} else if (
this.match(tt.templateMiddle) ||
this.match(tt.templateNonTail) ||
this.match(tt.templateTail)
) {
const result = this.parseTaggedTemplateExpression(
Expand Down
14 changes: 7 additions & 7 deletions packages/babel-parser/src/tokenizer/index.js
Expand Up @@ -916,7 +916,7 @@ export default class Tokenizer extends ParserErrors {
return;

case charCodes.graveAccent:
this.readTmplToken();
this.readTemplateToken();
return;

case charCodes.digit0: {
Expand Down Expand Up @@ -1369,18 +1369,18 @@ export default class Tokenizer extends ParserErrors {
this.finishToken(tt.string, out);
}

// Reads template string tokens.

readTemplateMiddle(): void {
// Reads tempalte continuation `}...`
readTemplateContinuation(): void {
if (!this.match(tt.braceR)) {
this.unexpected(this.state.start, tt.braceR);
}
// rewind pos to `}`
this.state.pos--;
this.readTmplToken();
this.readTemplateToken();
}

readTmplToken(): void {
// Reads template string tokens.
readTemplateToken(): void {
let out = "",
chunkStart = this.state.pos, // eat '`' or `}`
containsInvalid = false;
Expand All @@ -1402,7 +1402,7 @@ export default class Tokenizer extends ParserErrors {
) {
this.state.pos += 2; // eat '${'
out += this.input.slice(chunkStart, this.state.pos);
this.finishToken(tt.templateMiddle, containsInvalid ? null : out);
this.finishToken(tt.templateNonTail, containsInvalid ? null : out);
return;
}
if (ch === charCodes.backslash) {
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-parser/src/tokenizer/types.js
Expand Up @@ -159,7 +159,7 @@ export const tt: { [name: string]: TokenType } = {
backQuote: createToken("`", { startsExpr }),
dollarBraceL: createToken("${", { beforeExpr, startsExpr }),
templateTail: createToken("...`", { startsExpr }),
templateMiddle: createToken("...${", { beforeExpr, startsExpr }),
templateNonTail: createToken("...${", { beforeExpr, startsExpr }),
at: createToken("@"),
hash: createToken("#", { startsExpr }),

Expand Down
2 changes: 1 addition & 1 deletion packages/babel-parser/src/util/location.js
Expand Up @@ -54,7 +54,7 @@ export function getLineInfo(input: string, offset: number): Position {
/**
* creates a new position with a non-zero column offset from the given position.
* This function should be only be used when we create AST node out of the token
* boundaries, such as TemplateElement ends before tt.templateMiddle. This
* boundaries, such as TemplateElement ends before tt.templateNonTail. This
* function does not skip whitespaces.
*
* @export
Expand Down

0 comments on commit 491c921

Please sign in to comment.