Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit df27d54

Browse files
proposal-pipe: Add support for ^^ and @@ topics (#13973)
Co-authored-by: Nicolò Ribaudo <[email protected]>
1 parent b91c3e1 commit df27d54

File tree

694 files changed

+13369
-19
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

694 files changed

+13369
-19
lines changed

eslint/babel-eslint-parser/src/convert/convertTokens.cjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ function convertToken(token, source, tl) {
140140
label === tl.bracketHashL ||
141141
label === tl.bracketBarL ||
142142
label === tl.bracketBarR ||
143+
label === tl.doubleCaret ||
144+
label === tl.doubleAt ||
143145
type.isAssign
144146
) {
145147
token.type = "Punctuator";

eslint/babel-eslint-parser/test/index.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,31 @@ describe("Babel and Espree", () => {
691691
expect(babylonAST.tokens[16]).toMatchObject(topicToken);
692692
});
693693

694+
it.each(["^", "%", "^^", "@@"])("pipeline %s topic token", tok => {
695+
const code = `
696+
x |> ${tok}
697+
y |> ${tok}[0]
698+
`;
699+
700+
const babylonAST = parseForESLint(code, {
701+
eslintVisitorKeys: true,
702+
eslintScopeManager: true,
703+
babelOptions: {
704+
filename: "test.js",
705+
parserOpts: {
706+
plugins: [
707+
["pipelineOperator", { proposal: "hack", topicToken: tok }],
708+
],
709+
tokens: true,
710+
},
711+
},
712+
}).ast;
713+
714+
const topicToken = { type: "Punctuator", value: tok };
715+
expect(babylonAST.tokens[2]).toMatchObject(topicToken);
716+
expect(babylonAST.tokens[5]).toMatchObject(topicToken);
717+
});
718+
694719
it("empty program with line comment", () => {
695720
parseAndAssertSame("// single comment");
696721
});

packages/babel-generator/src/generators/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ export function DecimalLiteral(this: Printer, node: t.DecimalLiteral) {
238238
}
239239

240240
// Hack pipe operator
241-
const validTopicTokenSet = new Set(["^", "%", "#"]);
241+
const validTopicTokenSet = new Set(["^^", "@@", "^", "%", "#"]);
242242
export function TopicReference(this: Printer) {
243243
const { topicToken } = this.format;
244244

packages/babel-generator/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ export interface GeneratorOptions {
203203
* For use with the Hack-style pipe operator.
204204
* Changes what token is used for pipe bodies’ topic references.
205205
*/
206-
topicToken?: "^" | "%" | "#";
206+
topicToken?: "^^" | "@@" | "^" | "%" | "#";
207207
}
208208

209209
export interface GeneratorResult {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2 + 3 |> @@.toString(16);
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"plugins": [["pipelineOperator", { "proposal": "hack", "topicToken": "@@" }]],
3+
"topicToken": "@@"
4+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2 + 3 |> @@.toString(16);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2 + 3 |> ^^.toString(16);
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"plugins": [["pipelineOperator", { "proposal": "hack", "topicToken": "^^" }]],
3+
"topicToken": "^^"
4+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2 + 3 |> ^^.toString(16);

0 commit comments

Comments
 (0)