Skip to content

Commit

Permalink
replace lineBreak.test by hasPrecedingLingBreak
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Aug 10, 2020
1 parent 008fe25 commit 41f4397
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 15 deletions.
4 changes: 1 addition & 3 deletions packages/babel-parser/src/parser/statement.js
Expand Up @@ -629,9 +629,7 @@ export default class StatementParser extends ExpressionParser {

parseThrowStatement(node: N.ThrowStatement): N.ThrowStatement {
this.next();
if (
lineBreak.test(this.input.slice(this.state.lastTokEnd, this.state.start))
) {
if (this.hasPrecedingLineBreak()) {
this.raise(this.state.lastTokEnd, Errors.NewlineAfterThrow);
}
node.argument = this.parseExpression();
Expand Down
6 changes: 1 addition & 5 deletions packages/babel-parser/src/tokenizer/context.js
Expand Up @@ -5,7 +5,6 @@
// See https://github.com/mozilla/sweet.js/wiki/design

import { types as tt } from "./types";
import { lineBreak } from "../util/whitespace";

export class TokContext {
constructor(
Expand Down Expand Up @@ -111,10 +110,7 @@ tt._function.updateContext = tt._class.updateContext = function (prevType) {
prevType.beforeExpr &&
prevType !== tt.semi &&
prevType !== tt._else &&
!(
prevType === tt._return &&
lineBreak.test(this.input.slice(this.state.lastTokEnd, this.state.start))
) &&
!(prevType === tt._return && this.hasPrecedingLineBreak()) &&
!(
(prevType === tt.colon || prevType === tt.braceL) &&
this.curContext() === types.b_stat
Expand Down
10 changes: 3 additions & 7 deletions packages/babel-parser/src/tokenizer/index.js
Expand Up @@ -114,6 +114,7 @@ export default class Tokenizer extends ParserErrors {
// Forward-declarations
// parser/util.js
/*::
+hasPrecedingLineBreak: () => boolean;
+unexpected: (pos?: ?number, messageOrType?: string | TokenType) => empty;
+expectPlugin: (name: string, pos?: ?number) => true;
*/
Expand Down Expand Up @@ -603,10 +604,7 @@ export default class Tokenizer extends ParserErrors {
next === charCodes.dash &&
!this.inModule &&
this.input.charCodeAt(this.state.pos + 2) === charCodes.greaterThan &&
(this.state.lastTokEnd === 0 ||
lineBreak.test(
this.input.slice(this.state.lastTokEnd, this.state.pos),
))
(this.state.lastTokEnd === 0 || this.hasPrecedingLineBreak())
) {
// A `-->` line comment
this.skipLineComment(3);
Expand Down Expand Up @@ -1525,9 +1523,7 @@ export default class Tokenizer extends ParserErrors {
prevType === tt._return ||
(prevType === tt.name && this.state.exprAllowed)
) {
return lineBreak.test(
this.input.slice(this.state.lastTokEnd, this.state.start),
);
return this.hasPrecedingLineBreak();
}

if (
Expand Down

0 comments on commit 41f4397

Please sign in to comment.