Skip to content
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

Add support for the "Hack" pipeline proposal #13191

Merged
Merged
Show file tree
Hide file tree
Changes from 49 commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
5701fd4
Add comment about Hack-style pipeline arrow-function early error
js-choi Apr 8, 2021
740cec3
Remove obsoleted smart-mix pipe early errors about sequence expressions
js-choi Apr 8, 2021
9277286
Remove obsoleted smart-mix pipe early errors about statements
js-choi Apr 8, 2021
b18f23e
Remove obsoleted smart-mix pipe's bare-style's parser tests
js-choi Apr 8, 2021
4019b6d
Remove obsoleted smart-mix pipe's bare style from parser
js-choi Apr 8, 2021
173f2ff
Rename pipe-operator parser fixture titles
js-choi Apr 8, 2021
d83b79d
Rename "smart" pipe-proposal option to "hack"
js-choi Apr 8, 2021
8fb52c4
Simplify Hack-style pipe AST
js-choi Apr 8, 2021
d436a83
babel-generator: Add tests for topic reference
js-choi Apr 9, 2021
b5be14e
Rename “primary topic reference” to “topic reference”
js-choi Apr 13, 2021
69fbd55
Change new error messages to match consistent Babel style
js-choi Apr 9, 2021
e788c5e
More tests for Hack-style pipes in anticipation of other topic tokens
js-choi Apr 9, 2021
f58fcf6
Hack pipes now require that a topic token be specified
js-choi Apr 9, 2021
11a7a49
Revert removal of pipe-operator smart mix
js-choi Apr 13, 2021
5ae15aa
Rename Hack-pipe test fixtures
js-choi Apr 13, 2021
8de5e4f
Fix failing pipe tests on Node 6
js-choi Apr 13, 2021
e325241
Add warning about deprecation of smart-mix pipe
js-choi Apr 14, 2021
bd55376
Merge main into proposal-hack-pipes
js-choi May 25, 2021
8e2cce8
Update Hack-pipe test fixtures
js-choi May 25, 2021
a0a409b
Require Node 8 for pipe-operator tests with await
js-choi May 25, 2021
0dbc5e2
parser: Fix regression in smart-mix pipe node locations
js-choi May 25, 2021
53612dd
parser: Fix Flow error for optional pipe-proposal option
js-choi May 25, 2021
0c442a2
generator: Fix missing TS/Flow Format.topicToken declaration
js-choi May 25, 2021
1c07c3d
parser: Revert changes to smart-mix error messages
js-choi May 25, 2021
0b9b2d8
parser: Add back tests for smart-mix pipes
js-choi May 25, 2021
93a5b4c
parser: Rename #-token Hack-pipe test for consistency
js-choi May 25, 2021
619b324
parser: Fix pipe-proposal unbound-topic error message
js-choi May 25, 2021
cf0fd96
parser: Extract parseTopicReference into another method
js-choi May 27, 2021
2999418
parser: Add support for bare yield expressions in Hack-pipe bodies
js-choi May 27, 2021
5063459
parser spec: Add deprecation warning for smart-mix pipe types
js-choi May 27, 2021
c32e734
parser: Add tests for topic reference # without enabling pipe plugin
js-choi May 27, 2021
c711d6c
plugin-proposal-pipeline: Tweak Hack-pipe test for object literal
js-choi May 27, 2021
d68afce
parser: Fix name of test smart-proposal-arrow-function-unparenthesized
js-choi May 27, 2021
a0efcbe
parser: Hack pipes now support assignment expressions in bodies
js-choi May 27, 2021
85a146b
parser: Drop support for assignment/yield/arrow-ƒ Hack-pipe bodies
js-choi May 27, 2021
271b9bf
parser: Remove not-working Hack-pipe error message on = expressions
js-choi May 28, 2021
6e4f74f
parser: Revert changes to smart-mix pipe error codes
js-choi May 28, 2021
bbbe108
parser: Simplify parseTopicReference
js-choi May 28, 2021
6d909af
plugin-proposal-pipeline: Inline ƒs in Hack visitor
js-choi May 28, 2021
c9823c5
plugin-proposal-pipeline: Revert stylistic tweaks to smartVisitor
js-choi May 28, 2021
217c59a
generator: Restore missing smart-mix pipe tests
js-choi May 28, 2021
006552b
parser: Restore missing smart-mix tests
js-choi May 28, 2021
f9a1f13
plugin-proposal-pipeline: Restore missing smart-mix tests
js-choi May 28, 2021
28e191a
plugin-proposal-pipeline: Minor test renaming
js-choi May 28, 2021
24218dd
parser/plugin-pipeline: Tests for topic-ref identity
js-choi May 28, 2021
6b683ea
plugin-pipeline: Fix transform when Hack pipe body is topic identity
js-choi May 28, 2021
2bd98d2
plugin-pipeline: Add input/output.js fixtures
js-choi May 28, 2021
fc17668
parser: Improve documentation of parseTopicReference
js-choi May 28, 2021
518cf04
proposal-pipeline: Test no-proposal case
js-choi May 28, 2021
0f83c10
parser: Add tests for Hack-pipes in variable declarations vs. assignment
js-choi May 28, 2021
cd8a457
parser: Hack-pipe humane error for assignment expressions
js-choi May 28, 2021
43dd9af
parser: Make invalid topic references fatal errors
js-choi May 28, 2021
02c8548
parser: Satisfy Flow complaint about unhandled else branch
js-choi May 28, 2021
92bcdb6
parser: Remove unused inPipeline flag
js-choi May 28, 2021
46d9f8c
parser: Restore `this.withTopicForbiddingContext` for smart-mix pipes
js-choi May 28, 2021
e18901c
parser: Minor registerTopicReference comment update
js-choi May 27, 2021
5f17877
proposal-pipeline: Test Hack pipe with class + private properties
js-choi May 29, 2021
01ca985
parser: Fix pipe topicToken optional typing
js-choi May 29, 2021
de195dc
parser: Restore erroneously removed smart-mix node types
js-choi May 29, 2021
6aaccd4
parser: Restore pipe tests with for-await-of loops
js-choi May 29, 2021
a5fef32
parser: Rename pipe tests to note other transformations
js-choi May 29, 2021
eeb54fd
parser: Add Hack-pipe tests for nontransformed await
js-choi May 29, 2021
2f70ff9
parser: Unbound-topic error is now recoverable again
js-choi May 30, 2021
6d1c89b
parser: Restore smart-mix pipe error when pipe head is comma sequence
js-choi May 30, 2021
62c52eb
proposal-pipeline: Restore missing smart-mix exec fixture
js-choi May 30, 2021
7cdf3ac
parser: Check conflict between hash topic tokens and tuples
js-choi Jun 1, 2021
640d974
parser/plugin-pipeline: Minor hash-tuple test changes
js-choi Jun 2, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
17 changes: 17 additions & 0 deletions packages/babel-generator/src/generators/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,23 @@ export function DecimalLiteral(this: Printer, node: t.DecimalLiteral) {
this.word(node.value + "m");
}

// Hack pipe operator
export function TopicReference(this: Printer) {
const { topicToken } = this.format;
switch (topicToken) {
case "#":
this.token("#");
break;

default: {
const givenTopicTokenJSON = JSON.stringify(topicToken);
const message = `The "topicToken" generator option must be "#" (${givenTopicTokenJSON} received instead).`;
throw new Error(message);
}
}
}

// Smart-mix pipe operator
export function PipelineTopicExpression(
this: Printer,
node: t.PipelineTopicExpression,
Expand Down
7 changes: 7 additions & 0 deletions packages/babel-generator/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ function normalizeOptions(code, opts): Format {
...opts.jsescOption,
},
recordAndTupleSyntaxType: opts.recordAndTupleSyntaxType,
topicToken: opts.topicToken,
};

if (!process.env.BABEL_8_BREAKING) {
Expand Down Expand Up @@ -197,6 +198,12 @@ export interface GeneratorOptions {
*/
wrap?: boolean;
};

/**
* For use with the Hack-style pipe operator.
* Changes what token is used for pipe bodies’ topic references.
*/
topicToken?: "#";
}

export interface GeneratorResult {
Expand Down
5 changes: 5 additions & 0 deletions packages/babel-generator/src/printer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ export type Format = {
recordAndTupleSyntaxType: "bar" | "hash";
jsescOption;
jsonCompatibleStrings?;
/**
* For use with the Hack-style pipe operator.
* Changes what token is used for pipe bodies’ topic references.
*/
topicToken?: "#";
};

class Printer {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"plugins": [["pipelineOperator", { "proposal": "smart" }], "doExpressions"]
"plugins": [["pipelineOperator", { "proposal": "smart" }]]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2 + 3 |> #.toString(16);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2 + 3 |> #.toString(16);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2 + 3 |> #.toString(16);
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"plugins": [["pipelineOperator", { "proposal": "hack", "topicToken": "#" }]],
"topicToken": "#"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2 + 3 |> #.toString(16);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2 + 3 |> #.toString(16);
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"plugins": [["pipelineOperator", { "proposal": "hack", "topicToken": "#" }]],
"topicToken": "invalid",
"throws": "The \"topicToken\" generator option must be \"#\" (\"invalid\" received instead)."
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2 + 3 |> #.toString(16);
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"plugins": [["pipelineOperator", { "proposal": "hack", "topicToken": "#" }]],
"throws": "The \"topicToken\" generator option must be \"#\" (undefined received instead)."
}
109 changes: 61 additions & 48 deletions packages/babel-parser/ast/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -960,54 +960,6 @@ interface BindExpression <: Expression {

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.

#### PipelineBody

```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";
callee: Expression;
}
```

## ConditionalExpression

```js
Expand Down Expand Up @@ -1099,6 +1051,17 @@ interface ModuleExpression <: Expression {

A inline module expression proposed in https://github.com/tc39/proposal-js-module-blocks.

## TopicReference

```js
interface TopicReference <: Expression {
type: "TopicReference";
}
```

A topic reference to be used inside the body of
a [Hack-style pipe expression](https://github.com/js-choi/proposal-hack-pipes).

# Template Literals

## TemplateLiteral
Expand Down Expand Up @@ -1431,3 +1394,53 @@ interface ExportAllDeclaration <: ModuleDeclaration {
```

An export batch declaration, e.g., `export * from "mod";`.

### Smart-mix pipelines

These types are **deprecated**.
They are used by the deprecated smart-mix pipe operator to determine
the type of a pipe expression's the body expression.
The Hack and F# pipe operators use simple `BinaryExpression`s.

#### PipelineBody

```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";
callee: Expression;
}
17 changes: 16 additions & 1 deletion packages/babel-parser/src/parser/error-message.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,20 @@ export const ErrorMessages = makeErrorTemplates(
ParamDupe: "Argument name clash.",
PatternHasAccessor: "Object pattern can't contain getter or setter.",
PatternHasMethod: "Object pattern can't contain methods.",
PipeBodyIsTighter:
"Unexpected %0 after pipeline body; any %0 expression acting as Hack-style pipe body must be parenthesized due to its loose operator precedence.",

PipeTopicRequiresHackPipes:
'Topic reference is used, but the pipelineOperator plugin was not passed a "proposal": "hack" or "smart" option.',
PipeTopicUnbound:
"Topic reference is unbound; it must be inside a Hack-style pipe body.",
PipeTopicUnused:
"Hack-style pipe body does not contain a topic reference; Hack-style pipes must use topic at least once.",

// Messages whose codes start with “Pipeline” or “PrimaryTopic”
// are retained for backwards compatibility
// with the deprecated smart-mix pipe operator proposal plugin.
// They are subject to removal in a future major version.
PipelineBodyNoArrow:
'Unexpected arrow "=>" after pipeline body; arrow function in pipeline body must be parenthesized.',
PipelineBodySequenceExpression:
Expand All @@ -145,7 +159,8 @@ export const ErrorMessages = makeErrorTemplates(
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 used, but the pipelineOperator plugin was not passed a "proposal": "hack" or "smart" 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