Skip to content

Commit 51e925d

Browse files
Transform flow
1 parent 2f7db6a commit 51e925d

File tree

1 file changed

+17
-19
lines changed

1 file changed

+17
-19
lines changed

src/languages/flow.js

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,17 @@
11
import { toArray } from '../util/iterables.js';
2-
import { insertBefore } from '../util/language-util.js';
32
import javascript from './javascript.js';
43

54
/** @type {import('../types.d.ts').LanguageProto<'flow'>} */
65
export default {
76
id: 'flow',
87
base: javascript,
98
grammar ({ base }) {
10-
insertBefore(base, 'keyword', {
11-
'type': {
12-
pattern:
13-
/\b(?:[Bb]oolean|Function|[Nn]umber|[Ss]tring|[Ss]ymbol|any|mixed|null|void)\b/,
14-
alias: 'class-name',
15-
},
16-
});
17-
18-
insertBefore(base, 'operator', {
19-
'flow-punctuation': {
20-
pattern: /\{\||\|\}/,
21-
alias: 'punctuation',
22-
},
23-
});
24-
259
const fnVariable = /** @type {import('../types.d.ts').GrammarToken} */ (
2610
base['function-variable']
2711
);
2812
fnVariable.pattern =
2913
/(?!\s)[_$a-z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*=\s*(?:function\b|(?:\([^()]*\)(?:\s*:\s*\w+)?|(?!\s)[_$a-z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*)\s*=>))/i;
3014

31-
delete base['parameter'];
32-
3315
return {
3416
'keyword': [
3517
{
@@ -41,8 +23,24 @@ export default {
4123
/(^|[^$]\B)\$(?:Diff|Enum|Exact|Keys|ObjMap|PropertyType|Record|Shape|Subtype|Supertype|await)\b(?!\$)/,
4224
lookbehind: true,
4325
},
44-
...toArray(base.keyword),
26+
...toArray(/** @type {import('../types.d.ts').GrammarTokens} */ (base).keyword),
4527
],
28+
$insertBefore: {
29+
'keyword': {
30+
'type': {
31+
pattern:
32+
/\b(?:[Bb]oolean|Function|[Nn]umber|[Ss]tring|[Ss]ymbol|any|mixed|null|void)\b/,
33+
alias: 'class-name',
34+
},
35+
},
36+
'operator': {
37+
'flow-punctuation': {
38+
pattern: /\{\||\|\}/,
39+
alias: 'punctuation',
40+
},
41+
},
42+
},
43+
$delete: ['parameter'],
4644
};
4745
},
4846
};

0 commit comments

Comments
 (0)