Skip to content

Commit

Permalink
Rename "smart" pipe-proposal option to "hack"
Browse files Browse the repository at this point in the history
  • Loading branch information
js-choi committed Apr 14, 2021
1 parent 173f2ff commit d83b79d
Show file tree
Hide file tree
Showing 218 changed files with 205 additions and 435 deletions.
@@ -0,0 +1,3 @@
{
"plugins": [["pipelineOperator", { "proposal": "hack" }], "doExpressions"]
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

43 changes: 4 additions & 39 deletions packages/babel-parser/ast/spec.md
Expand Up @@ -962,48 +962,13 @@ If `object` is `null`, then `callee` should be a `MemberExpression`.

### Pipeline

These nodes are used by the Smart Pipeline to determine the type of the expression in a Pipeline Operator Expression. The F# Pipeline uses simple `BinaryExpression`s.
These nodes are used by the Hack-style pipe operator. (The F# Pipeline uses simple `BinaryExpression`s and `AwaitExpression`s.)

#### PipelineBody
#### PipeBody

```js
interface PipelineBody <: NodeBase {
type: "PipelineBody";
}
```

#### PipelineBareFunctionBody

```js
interface PipelineBody <: NodeBase {
type: "PipelineBareFunctionBody";
callee: Expression;
}
```

#### PipelineBareConstructorBody

```js
interface PipelineBareConstructorBody <: NodeBase {
type: "PipelineBareConstructorBody";
callee: Expression;
}
```

#### PipelineBareAwaitedFunctionBody

```js
interface PipelineBareConstructorBody <: NodeBase {
type: "PipelineTopicBody";
expression: Expression;
}
```

#### PipelineTopicBody

```js
interface PipelineBareConstructorBody <: NodeBase {
type: "PipelineBareAwaitedFunctionBody";
interface PipeBody <: NodeBase {
type: "PipeBody";
callee: Expression;
}
```
Expand Down
12 changes: 6 additions & 6 deletions packages/babel-parser/src/parser/error-message.js
Expand Up @@ -129,14 +129,14 @@ export const ErrorMessages = Object.freeze({
ParamDupe: "Argument name clash",
PatternHasAccessor: "Object pattern can't contain getter or setter",
PatternHasMethod: "Object pattern can't contain methods",
PipelineBodyNoArrow:
'Unexpected arrow "=>" after pipeline body; arrow function in pipeline body must be parenthesized',
PipeBodyCannotBeArrow:
'Unexpected arrow "=>" after pipeline body; arrow function acting as pipe body must be parenthesized due to operator precedence',
PipelineTopicUnused:
"Pipeline is in topic style but does not use topic reference",
"Hack-style pipe body does not contain a topic reference; Hack-style pipes must use topic at least once",
PrimaryTopicNotAllowed:
"Topic reference was used in a lexical context without topic binding",
PrimaryTopicRequiresSmartPipeline:
"Primary Topic Reference found but pipelineOperator not passed 'smart' for 'proposal' option.",
"Topic reference is unbound; it must be inside a Hack-style pipe body",
PrimaryTopicRequiresHackPipes:
"Topic reference is used, but the pipelineOperator plugin was not passed a 'proposal': 'hack' option.",
PrivateInExpectedIn:
"Private names are only allowed in property accesses (`obj.#%0`) or in `in` expressions (`#%0 in obj`)",
PrivateNameRedeclaration: "Duplicate private name #%0",
Expand Down
34 changes: 16 additions & 18 deletions packages/babel-parser/src/parser/expression.js
Expand Up @@ -459,9 +459,9 @@ export default class ExpressionParser extends LValParser {
switch (op) {
case tt.pipeline:
switch (this.getPluginOption("pipelineOperator", "proposal")) {
case "smart":
return this.withTopicPermittingContext(() => {
return this.parseSmartPipelineBody(
case "hack":
return this.withTopicBindingContext(() => {
return this.parseHackPipelineBody(
this.parseExprOpBaseRightExpr(op, prec),
startPos,
startLoc,
Expand Down Expand Up @@ -1152,10 +1152,8 @@ export default class ExpressionParser extends LValParser {
if (this.state.inPipeline) {
node = this.startNode();

if (
this.getPluginOption("pipelineOperator", "proposal") !== "smart"
) {
this.raise(node.start, Errors.PrimaryTopicRequiresSmartPipeline);
if (this.getPluginOption("pipelineOperator", "proposal") !== "hack") {
this.raise(node.start, Errors.PrimaryTopicRequiresHackPipes);
}

this.next();
Expand Down Expand Up @@ -2465,32 +2463,32 @@ export default class ExpressionParser extends LValParser {
return this.finishNode(node, "YieldExpression");
}

parseSmartPipelineBody(
parseHackPipelineBody(
childExpression: N.Expression,
startPos: number,
startLoc: Position,
): N.PipelineBody {
this.checkSmartPipelineBodyEarlyErrors();
this.checkHackPipelineBodyEarlyErrors();

return this.parseSmartPipelineBodyInStyle(
return this.parseHackPipelineBodyInStyle(
childExpression,
startPos,
startLoc,
);
}

checkSmartPipelineBodyEarlyErrors(): void {
checkHackPipelineBodyEarlyErrors(): void {
if (this.match(tt.arrow)) {
// If the following token is invalidly `=>`, then throw a human-friendly error
// instead of something like 'Unexpected token, expected ";"'.
// For example, `x => x |> y => %` groups into `x => (x |> y) => %`,
// and `(x |> y) => %` is an invalid arrow function.
// This is because Hack-style `|>` has tighter precedence than `=>`.
throw this.raise(this.state.start, Errors.PipelineBodyNoArrow);
throw this.raise(this.state.start, Errors.PipeBodyCannotBeArrow);
}
}

parseSmartPipelineBodyInStyle(
parseHackPipelineBodyInStyle(
childExpression: N.Expression,
startPos: number,
startLoc: Position,
Expand All @@ -2506,13 +2504,13 @@ export default class ExpressionParser extends LValParser {
return this.finishNode(bodyNode, "PipelineTopicExpression");
}

// Enable topic references from outer contexts within smart pipeline bodies.
// Enable topic references from outer contexts within Hack-style pipe bodies.
// The function modifies the parser's topic-context state to enable or disable
// the use of topic references with the smartPipelines plugin. They then run a
// callback, then they reset the parser to the old topic-context state that it
// had before the function was called.
// the use of topic references.
// The function then calls a callback, then resets the parser
// to the old topic-context state that it had before the function was called.

withTopicPermittingContext<T>(callback: () => T): T {
withTopicBindingContext<T>(callback: () => T): T {
const outerContextTopicState = this.state.topicContext;
this.state.topicContext = {
// Enable the use of the primary topic reference.
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-parser/src/plugin-utils.js
Expand Up @@ -38,7 +38,7 @@ export function getPluginOption(
return null;
}

const PIPELINE_PROPOSALS = ["minimal", "smart", "fsharp"];
const PIPELINE_PROPOSALS = ["minimal", "fsharp", "hack"];
const RECORD_AND_TUPLE_SYNTAX_TYPES = ["hash", "bar"];

export function validatePlugins(plugins: PluginList) {
Expand Down
4 changes: 2 additions & 2 deletions packages/babel-parser/src/tokenizer/state.js
Expand Up @@ -68,13 +68,13 @@ export default class State {
isDeclareContext: boolean = false;
inAbstractClass: boolean = false;

// For the smartPipelines plugin:
// For the Hack-style pipelines plugin
topicContext: TopicContextState = {
maxNumOfResolvableTopics: 0,
maxTopicIndex: null,
};

// For the F# plugin
// For the F#-style pipelines plugin
soloAwait: boolean = false;
inFSharpPipelineDirectBody: boolean = false;

Expand Down
Expand Up @@ -2,8 +2,8 @@
"type": "File",
"start":0,"end":10,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":10}},
"errors": [
"SyntaxError: Primary Topic Reference found but pipelineOperator not passed 'smart' for 'proposal' option. (1:5)",
"SyntaxError: Topic reference was used in a lexical context without topic binding (1:5)"
"SyntaxError: Topic reference is used, but the pipelineOperator plugin was not passed a 'proposal': 'hack' option. (1:5)",
"SyntaxError: Topic reference is unbound; it must be inside a Hack-style pipe body (1:5)"
],
"program": {
"type": "Program",
Expand Down
@@ -0,0 +1,3 @@
{
"plugins": [["pipelineOperator", { "proposal": "hack" }]]
}
@@ -0,0 +1,3 @@
{
"plugins": [["pipelineOperator", { "proposal": "hack" }]]
}
@@ -0,0 +1,3 @@
{
"plugins": [["pipelineOperator", { "proposal": "hack" }]]
}
Expand Up @@ -2,7 +2,7 @@
"type": "File",
"start":0,"end":14,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":14}},
"errors": [
"SyntaxError: Pipeline is in topic style but does not use topic reference (1:9)"
"SyntaxError: Hack-style pipe body does not contain a topic reference; Hack-style pipes must use topic at least once (1:9)"
],
"program": {
"type": "Program",
Expand Down
@@ -0,0 +1,3 @@
{
"plugins": [["pipelineOperator", { "proposal": "hack" }]]
}
@@ -0,0 +1,11 @@
{
"plugins": [
[
"pipelineOperator",
{
"proposal": "hack"
}
]
],
"throws": "Unexpected arrow \"=>\" after pipeline body; arrow function acting as pipe body must be parenthesized due to operator precedence (1:8)"
}
@@ -0,0 +1,3 @@
{
"plugins": [["pipelineOperator", { "proposal": "hack" }]]
}
@@ -0,0 +1,3 @@
{
"plugins": [["pipelineOperator", { "proposal": "hack" }]]
}
Expand Up @@ -2,7 +2,7 @@
"type": "File",
"start":0,"end":13,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":13}},
"errors": [
"SyntaxError: Pipeline is in topic style but does not use topic reference (1:9)"
"SyntaxError: Hack-style pipe body does not contain a topic reference; Hack-style pipes must use topic at least once (1:9)"
],
"program": {
"type": "Program",
Expand Down
@@ -0,0 +1,3 @@
{
"plugins": [["pipelineOperator", { "proposal": "hack" }], "doExpressions"]
}
@@ -1,6 +1,6 @@
{
"plugins": [
["pipelineOperator", { "proposal": "smart" }],
["pipelineOperator", { "proposal": "hack" }],
"doExpressions",
"asyncGenerators"
]
Expand Down
@@ -0,0 +1,3 @@
{
"plugins": [["pipelineOperator", { "proposal": "hack" }], "doExpressions"]
}
@@ -0,0 +1,3 @@
{
"plugins": [["pipelineOperator", { "proposal": "hack" }], "doExpressions"]
}
@@ -0,0 +1,3 @@
{
"plugins": [["pipelineOperator", { "proposal": "hack" }], "doExpressions"]
}
@@ -0,0 +1,3 @@
{
"plugins": [["pipelineOperator", { "proposal": "hack" }], "doExpressions"]
}
@@ -0,0 +1,3 @@
{
"plugins": [["pipelineOperator", { "proposal": "hack" }], "doExpressions"]
}
@@ -0,0 +1,3 @@
{
"plugins": [["pipelineOperator", { "proposal": "hack" }], "doExpressions"]
}
@@ -0,0 +1,3 @@
{
"plugins": [["pipelineOperator", { "proposal": "hack" }], "doExpressions"]
}
@@ -0,0 +1,3 @@
{
"plugins": [["pipelineOperator", { "proposal": "hack" }], "doExpressions"]
}
@@ -0,0 +1,3 @@
{
"plugins": [["pipelineOperator", { "proposal": "hack" }], "doExpressions"]
}
@@ -0,0 +1,3 @@
{
"plugins": [["pipelineOperator", { "proposal": "hack" }], "doExpressions"]
}
@@ -0,0 +1,3 @@
{
"plugins": [["pipelineOperator", { "proposal": "hack" }], "doExpressions"]
}
@@ -0,0 +1,3 @@
{
"plugins": [["pipelineOperator", { "proposal": "hack" }], "doExpressions"]
}
@@ -0,0 +1,3 @@
{
"plugins": [["pipelineOperator", { "proposal": "hack" }], "doExpressions"]
}
@@ -0,0 +1,3 @@
{
"plugins": [["pipelineOperator", { "proposal": "hack" }], "doExpressions"]
}
@@ -0,0 +1,3 @@
{
"plugins": [["pipelineOperator", { "proposal": "hack" }]]
}
@@ -0,0 +1,3 @@
{
"plugins": [["pipelineOperator", { "proposal": "hack" }]]
}
@@ -0,0 +1,3 @@
{
"plugins": [["pipelineOperator", { "proposal": "hack" }]]
}
@@ -0,0 +1,4 @@
{
"plugins": [["pipelineOperator", { "proposal": "hack" }]],
"throws": "Unexpected digit after hash token (1:5)"
}
@@ -0,0 +1,3 @@
{
"plugins": [["pipelineOperator", { "proposal": "hack" }], "pipelineOperator"]
}
@@ -0,0 +1,3 @@
{
"plugins": [["pipelineOperator", { "proposal": "hack" }]]
}
@@ -0,0 +1,3 @@
{
"plugins": [["pipelineOperator", { "proposal": "hack" }]]
}
Expand Up @@ -2,7 +2,7 @@
"type": "File",
"start":0,"end":22,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":22}},
"errors": [
"SyntaxError: Pipeline is in topic style but does not use topic reference (1:16)"
"SyntaxError: Hack-style pipe body does not contain a topic reference; Hack-style pipes must use topic at least once (1:16)"
],
"program": {
"type": "Program",
Expand Down
@@ -0,0 +1,3 @@
{
"plugins": [["pipelineOperator", { "proposal": "hack" }]]
}
Expand Up @@ -2,7 +2,7 @@
"type": "File",
"start":0,"end":18,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":18}},
"errors": [
"SyntaxError: Pipeline is in topic style but does not use topic reference (1:5)"
"SyntaxError: Hack-style pipe body does not contain a topic reference; Hack-style pipes must use topic at least once (1:5)"
],
"program": {
"type": "Program",
Expand Down
@@ -0,0 +1,3 @@
{
"plugins": [["pipelineOperator", { "proposal": "hack" }]]
}
@@ -0,0 +1,3 @@
{
"plugins": [["pipelineOperator", { "proposal": "hack" }]]
}

0 comments on commit d83b79d

Please sign in to comment.