From cd4b3fbffe12e5c3123cb6e040ea864a0034c498 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=2E=C2=A0S=2E=C2=A0Choi?= Date: Mon, 7 Jun 2021 10:09:12 -0400 Subject: [PATCH] parser: Fix Hack/smart-pipe error positions (#13426) --- packages/babel-parser/src/parser/expression.js | 8 ++++---- .../hack-hash-proposal-unbound-topic/output.json | 2 +- .../output.json | 2 +- .../output.json | 2 +- .../output.json | 2 +- .../output.json | 2 +- .../output.json | 2 +- .../output.json | 2 +- .../output.json | 2 +- .../output.json | 2 +- .../output.json | 2 +- .../output.json | 2 +- .../output.json | 2 +- .../output.json | 2 +- .../output.json | 2 +- .../smart-proposal-unbound-topic/output.json | 2 +- 16 files changed, 19 insertions(+), 19 deletions(-) diff --git a/packages/babel-parser/src/parser/expression.js b/packages/babel-parser/src/parser/expression.js index 35e0178ef2..8271ab1711 100644 --- a/packages/babel-parser/src/parser/expression.js +++ b/packages/babel-parser/src/parser/expression.js @@ -1264,7 +1264,7 @@ export default class ExpressionParser extends LValParser { if (pipeProposal) { // A pipe-operator proposal is active. - const tokenType = this.state.type; + const { type: tokenType, start } = this.state; if (this.testTopicReferenceConfiguration(pipeProposal, tokenType)) { // The token matches the plugin’s configuration. @@ -1295,10 +1295,10 @@ export default class ExpressionParser extends LValParser { // it is outside of a pipe body. // Raise recoverable errors. if (pipeProposal === "smart") { - this.raise(this.state.start, Errors.PrimaryTopicNotAllowed); + this.raise(start, Errors.PrimaryTopicNotAllowed); } else { // In this case, `pipeProposal === "hack"` is true. - this.raise(this.state.start, Errors.PipeTopicUnbound); + this.raise(start, Errors.PipeTopicUnbound); } } @@ -1306,7 +1306,7 @@ export default class ExpressionParser extends LValParser { } else { // The token does not match the plugin’s configuration. throw this.raise( - this.state.start, + start, Errors.PipeTopicUnconfiguredToken, tokenType.label, ); diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/hack-hash-proposal-unbound-topic/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/hack-hash-proposal-unbound-topic/output.json index d4bd9e0955..3146682dd7 100644 --- a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/hack-hash-proposal-unbound-topic/output.json +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/hack-hash-proposal-unbound-topic/output.json @@ -2,7 +2,7 @@ "type": "File", "start":0,"end":5,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":5}}, "errors": [ - "SyntaxError: Topic reference is unbound; it must be inside a pipe body. (1:5)" + "SyntaxError: Topic reference is unbound; it must be inside a pipe body. (1:4)" ], "program": { "type": "Program", diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/smart-proposal-class-expression-with-decorators/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/smart-proposal-class-expression-with-decorators/output.json index df5fa7b209..aa2d2b3b5e 100644 --- a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/smart-proposal-class-expression-with-decorators/output.json +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/smart-proposal-class-expression-with-decorators/output.json @@ -2,7 +2,7 @@ "type": "File", "start":0,"end":130,"loc":{"start":{"line":1,"column":0},"end":{"line":9,"column":2}}, "errors": [ - "SyntaxError: Topic reference was used in a lexical context without topic binding. (6:15)", + "SyntaxError: Topic reference was used in a lexical context without topic binding. (6:13)", "SyntaxError: Pipeline is in topic style but does not use topic reference. (1:9)" ], "program": { diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/smart-proposal-class-expression-with-private-property/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/smart-proposal-class-expression-with-private-property/output.json index c719c0f535..e8c0f1ae04 100644 --- a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/smart-proposal-class-expression-with-private-property/output.json +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/smart-proposal-class-expression-with-private-property/output.json @@ -2,7 +2,7 @@ "type": "File", "start":0,"end":94,"loc":{"start":{"line":1,"column":0},"end":{"line":7,"column":3}}, "errors": [ - "SyntaxError: Topic reference was used in a lexical context without topic binding. (5:13)", + "SyntaxError: Topic reference was used in a lexical context without topic binding. (5:11)", "SyntaxError: Pipeline is in topic style but does not use topic reference. (1:9)" ], "program": { diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/smart-proposal-class-expression-without-private-property/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/smart-proposal-class-expression-without-private-property/output.json index f06bdd1a2d..dcf7d7105d 100644 --- a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/smart-proposal-class-expression-without-private-property/output.json +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/smart-proposal-class-expression-without-private-property/output.json @@ -2,7 +2,7 @@ "type": "File", "start":0,"end":45,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":45}}, "errors": [ - "SyntaxError: Topic reference was used in a lexical context without topic binding. (1:40)", + "SyntaxError: Topic reference was used in a lexical context without topic binding. (1:39)", "SyntaxError: Pipeline is in topic style but does not use topic reference. (1:5)" ], "program": { diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/smart-proposal-do-transform-do-while-loop-and-topic-in-loop-body/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/smart-proposal-do-transform-do-while-loop-and-topic-in-loop-body/output.json index e50f728649..cce77f778a 100644 --- a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/smart-proposal-do-transform-do-while-loop-and-topic-in-loop-body/output.json +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/smart-proposal-do-transform-do-while-loop-and-topic-in-loop-body/output.json @@ -2,7 +2,7 @@ "type": "File", "start":0,"end":42,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":42}}, "errors": [ - "SyntaxError: Topic reference was used in a lexical context without topic binding. (1:23)", + "SyntaxError: Topic reference was used in a lexical context without topic binding. (1:22)", "SyntaxError: Pipeline is in topic style but does not use topic reference. (1:9)" ], "program": { diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/smart-proposal-do-transform-for-await-of-loop-and-topic-in-loop-body/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/smart-proposal-do-transform-for-await-of-loop-and-topic-in-loop-body/output.json index b5060f4103..cccbb6ee67 100644 --- a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/smart-proposal-do-transform-for-await-of-loop-and-topic-in-loop-body/output.json +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/smart-proposal-do-transform-for-await-of-loop-and-topic-in-loop-body/output.json @@ -2,7 +2,7 @@ "type": "File", "start":0,"end":77,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, "errors": [ - "SyntaxError: Topic reference was used in a lexical context without topic binding. (2:49)", + "SyntaxError: Topic reference was used in a lexical context without topic binding. (2:48)", "SyntaxError: Pipeline is in topic style but does not use topic reference. (2:11)" ], "program": { diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/smart-proposal-do-transform-for-classic-loop-and-topic-in-loop-body/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/smart-proposal-do-transform-for-classic-loop-and-topic-in-loop-body/output.json index dbab2d31d8..30756decb9 100644 --- a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/smart-proposal-do-transform-for-classic-loop-and-topic-in-loop-body/output.json +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/smart-proposal-do-transform-for-classic-loop-and-topic-in-loop-body/output.json @@ -2,7 +2,7 @@ "type": "File", "start":0,"end":49,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":49}}, "errors": [ - "SyntaxError: Topic reference was used in a lexical context without topic binding. (1:46)", + "SyntaxError: Topic reference was used in a lexical context without topic binding. (1:45)", "SyntaxError: Pipeline is in topic style but does not use topic reference. (1:9)" ], "program": { diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/smart-proposal-do-transform-for-in-loop-and-topic-in-loop-body/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/smart-proposal-do-transform-for-in-loop-and-topic-in-loop-body/output.json index 9d9eef3ec7..9c483cd137 100644 --- a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/smart-proposal-do-transform-for-in-loop-and-topic-in-loop-body/output.json +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/smart-proposal-do-transform-for-in-loop-and-topic-in-loop-body/output.json @@ -2,7 +2,7 @@ "type": "File", "start":0,"end":36,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":36}}, "errors": [ - "SyntaxError: Topic reference was used in a lexical context without topic binding. (1:33)", + "SyntaxError: Topic reference was used in a lexical context without topic binding. (1:32)", "SyntaxError: Pipeline is in topic style but does not use topic reference. (1:9)" ], "program": { diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/smart-proposal-do-transform-for-of-loop-and-topic-in-loop-body/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/smart-proposal-do-transform-for-of-loop-and-topic-in-loop-body/output.json index fef8f1a252..4241e8133c 100644 --- a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/smart-proposal-do-transform-for-of-loop-and-topic-in-loop-body/output.json +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/smart-proposal-do-transform-for-of-loop-and-topic-in-loop-body/output.json @@ -2,7 +2,7 @@ "type": "File", "start":0,"end":38,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":38}}, "errors": [ - "SyntaxError: Topic reference was used in a lexical context without topic binding. (1:35)", + "SyntaxError: Topic reference was used in a lexical context without topic binding. (1:34)", "SyntaxError: Pipeline is in topic style but does not use topic reference. (1:9)" ], "program": { diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/smart-proposal-do-transform-try-catch-finally-statements-and-topic-in-catch-clause/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/smart-proposal-do-transform-try-catch-finally-statements-and-topic-in-catch-clause/output.json index 3d8a3d363d..fe3ce80ecf 100644 --- a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/smart-proposal-do-transform-try-catch-finally-statements-and-topic-in-catch-clause/output.json +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/smart-proposal-do-transform-try-catch-finally-statements-and-topic-in-catch-clause/output.json @@ -2,7 +2,7 @@ "type": "File", "start":0,"end":78,"loc":{"start":{"line":1,"column":0},"end":{"line":4,"column":1}}, "errors": [ - "SyntaxError: Topic reference was used in a lexical context without topic binding. (3:33)" + "SyntaxError: Topic reference was used in a lexical context without topic binding. (3:32)" ], "program": { "type": "Program", diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/smart-proposal-do-transform-while-loop-topic-in-loop-body/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/smart-proposal-do-transform-while-loop-topic-in-loop-body/output.json index ccd647133f..bf6ede1d56 100644 --- a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/smart-proposal-do-transform-while-loop-topic-in-loop-body/output.json +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/smart-proposal-do-transform-while-loop-topic-in-loop-body/output.json @@ -2,7 +2,7 @@ "type": "File", "start":0,"end":38,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":38}}, "errors": [ - "SyntaxError: Topic reference was used in a lexical context without topic binding. (1:35)", + "SyntaxError: Topic reference was used in a lexical context without topic binding. (1:34)", "SyntaxError: Pipeline is in topic style but does not use topic reference. (1:9)" ], "program": { diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/smart-proposal-do-transform-with-block-topic-in-body/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/smart-proposal-do-transform-with-block-topic-in-body/output.json index 17c7f5b6be..7caf81f88f 100644 --- a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/smart-proposal-do-transform-with-block-topic-in-body/output.json +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/smart-proposal-do-transform-with-block-topic-in-body/output.json @@ -2,7 +2,7 @@ "type": "File", "start":0,"end":28,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":28}}, "errors": [ - "SyntaxError: Topic reference was used in a lexical context without topic binding. (1:25)", + "SyntaxError: Topic reference was used in a lexical context without topic binding. (1:24)", "SyntaxError: Pipeline is in topic style but does not use topic reference. (1:9)" ], "program": { diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/smart-proposal-function-definition-with-another-pipe-in-function-body/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/smart-proposal-function-definition-with-another-pipe-in-function-body/output.json index 11a8ace33f..9e45ecfa0c 100644 --- a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/smart-proposal-function-definition-with-another-pipe-in-function-body/output.json +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/smart-proposal-function-definition-with-another-pipe-in-function-body/output.json @@ -2,7 +2,7 @@ "type": "File", "start":0,"end":27,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":27}}, "errors": [ - "SyntaxError: Topic reference was used in a lexical context without topic binding. (1:21)", + "SyntaxError: Topic reference was used in a lexical context without topic binding. (1:19)", "SyntaxError: Pipeline is in topic style but does not use topic reference. (1:5)" ], "program": { diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/smart-proposal-function-definition-with-topic-in-function-body/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/smart-proposal-function-definition-with-topic-in-function-body/output.json index 92ea7f23e1..88eb526ee2 100644 --- a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/smart-proposal-function-definition-with-topic-in-function-body/output.json +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/smart-proposal-function-definition-with-topic-in-function-body/output.json @@ -2,7 +2,7 @@ "type": "File", "start":0,"end":22,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":22}}, "errors": [ - "SyntaxError: Topic reference was used in a lexical context without topic binding. (1:21)", + "SyntaxError: Topic reference was used in a lexical context without topic binding. (1:19)", "SyntaxError: Pipeline is in topic style but does not use topic reference. (1:5)" ], "program": { diff --git a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/smart-proposal-unbound-topic/output.json b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/smart-proposal-unbound-topic/output.json index 2f011bd014..f5ffb05fa8 100644 --- a/packages/babel-parser/test/fixtures/experimental/pipeline-operator/smart-proposal-unbound-topic/output.json +++ b/packages/babel-parser/test/fixtures/experimental/pipeline-operator/smart-proposal-unbound-topic/output.json @@ -2,7 +2,7 @@ "type": "File", "start":0,"end":5,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":5}}, "errors": [ - "SyntaxError: Topic reference was used in a lexical context without topic binding. (1:5)" + "SyntaxError: Topic reference was used in a lexical context without topic binding. (1:4)" ], "program": { "type": "Program",