File tree Expand file tree Collapse file tree 4 files changed +304
-2
lines changed
Expand file tree Collapse file tree 4 files changed +304
-2
lines changed Original file line number Diff line number Diff line change 3232 ]
3333 } ) ;
3434
35+ /**
36+ * Replaces the `<ID>` placeholder in the given pattern with a pattern for general JS identifiers.
37+ *
38+ * @param {string } source
39+ * @param {string } [flags]
40+ * @returns {RegExp }
41+ */
42+ function withId ( source , flags ) {
43+ return RegExp (
44+ source . replace ( / < I D > / g, function ( ) { return / [ _ $ a - z A - Z \xA0 - \uFFFF ] [ $ \w \xA0 - \uFFFF ] * / . source ; } ) ,
45+ flags ) ;
46+ }
47+ Prism . languages . insertBefore ( 'javascript' , 'keyword' , {
48+ 'imports' : {
49+ // https://tc39.es/ecma262/#sec-imports
50+ pattern : withId ( / ( \b i m p o r t \b \s * ) (?: < I D > (?: \s * , \s * (?: \* \s * a s \s + < I D > | \{ [ ^ { } ] * \} ) ) ? | \* \s * a s \s + < I D > | \{ [ ^ { } ] * \} ) (? = \s * \b f r o m \b ) / . source ) ,
51+ lookbehind : true ,
52+ inside : Prism . languages . javascript
53+ } ,
54+ 'exports' : {
55+ // https://tc39.es/ecma262/#sec-exports
56+ pattern : withId ( / ( \b e x p o r t \b \s * ) (?: \* (?: \s * a s \s + < I D > ) ? (? = \s * \b f r o m \b ) | \{ [ ^ { } ] * \} ) / . source ) ,
57+ lookbehind : true ,
58+ inside : Prism . languages . javascript
59+ }
60+ } ) ;
61+
3562 Prism . languages . javascript [ 'keyword' ] . unshift (
3663 {
3764 pattern : / \b (?: a s | d e f a u l t | e x p o r t | f r o m | i m p o r t ) \b / ,
6491
6592 Prism . languages . insertBefore ( 'javascript' , 'punctuation' , {
6693 'property-access' : {
67- pattern : / ( \. \s * ) # ? [ _ $ a - z A - Z \xA0 - \uFFFF ] [ $ \w \xA0 - \uFFFF ] * / ,
94+ pattern : withId ( / ( \. \s * ) # ? < I D > / . source ) ,
6895 lookbehind : true
6996 } ,
7097 'maybe-class-name' : {
Original file line number Diff line number Diff line change 1+ export * from "mod";
2+ export * as Foo from "mod";
3+ export {} from "mod";
4+ export {x} from "mod";
5+ export {d} from "mod";
6+ export {d,} from "mod";
7+ export {d as Foo, b as Bar} from "mod";
8+ export {d as Foo, b as Bar,} from "mod";
9+ export {}
10+ export {x}
11+ export {d}
12+ export {d,}
13+ export {d as Foo, b as Bar}
14+ export {d as Foo, b as Bar,}
15+
16+ ----------------------------------------------------
17+
18+ [
19+ ["keyword", "export"],
20+ ["exports", [
21+ ["operator", "*"]
22+ ]],
23+ ["keyword", "from"],
24+ ["string", "\"mod\""],
25+ ["punctuation", ";"],
26+ ["keyword", "export"],
27+ ["exports", [
28+ ["operator", "*"],
29+ ["keyword", "as"],
30+ ["maybe-class-name", "Foo"]
31+ ]],
32+ ["keyword", "from"],
33+ ["string", "\"mod\""],
34+ ["punctuation", ";"],
35+ ["keyword", "export"],
36+ ["exports", [
37+ ["punctuation", "{"],
38+ ["punctuation", "}"]
39+ ]],
40+ ["keyword", "from"],
41+ ["string", "\"mod\""],
42+ ["punctuation", ";"],
43+ ["keyword", "export"],
44+ ["exports", [
45+ ["punctuation", "{"],
46+ "x",
47+ ["punctuation", "}"]
48+ ]],
49+ ["keyword", "from"],
50+ ["string", "\"mod\""],
51+ ["punctuation", ";"],
52+ ["keyword", "export"],
53+ ["exports", [
54+ ["punctuation", "{"],
55+ "d",
56+ ["punctuation", "}"]
57+ ]],
58+ ["keyword", "from"],
59+ ["string", "\"mod\""],
60+ ["punctuation", ";"],
61+ ["keyword", "export"],
62+ ["exports", [
63+ ["punctuation", "{"],
64+ "d",
65+ ["punctuation", ","],
66+ ["punctuation", "}"]
67+ ]],
68+ ["keyword", "from"],
69+ ["string", "\"mod\""],
70+ ["punctuation", ";"],
71+ ["keyword", "export"],
72+ ["exports", [
73+ ["punctuation", "{"],
74+ "d ",
75+ ["keyword", "as"],
76+ ["maybe-class-name", "Foo"],
77+ ["punctuation", ","],
78+ " b ",
79+ ["keyword", "as"],
80+ ["maybe-class-name", "Bar"],
81+ ["punctuation", "}"]
82+ ]],
83+ ["keyword", "from"],
84+ ["string", "\"mod\""],
85+ ["punctuation", ";"],
86+ ["keyword", "export"],
87+ ["exports", [
88+ ["punctuation", "{"],
89+ "d ",
90+ ["keyword", "as"],
91+ ["maybe-class-name", "Foo"],
92+ ["punctuation", ","],
93+ " b ",
94+ ["keyword", "as"],
95+ ["maybe-class-name", "Bar"],
96+ ["punctuation", ","],
97+ ["punctuation", "}"]
98+ ]],
99+ ["keyword", "from"],
100+ ["string", "\"mod\""],
101+ ["punctuation", ";"],
102+ ["keyword", "export"],
103+ ["exports", [
104+ ["punctuation", "{"],
105+ ["punctuation", "}"]
106+ ]],
107+ ["keyword", "export"],
108+ ["exports", [
109+ ["punctuation", "{"],
110+ "x",
111+ ["punctuation", "}"]
112+ ]],
113+ ["keyword", "export"],
114+ ["exports", [
115+ ["punctuation", "{"],
116+ "d",
117+ ["punctuation", "}"]
118+ ]],
119+ ["keyword", "export"],
120+ ["exports", [
121+ ["punctuation", "{"],
122+ "d",
123+ ["punctuation", ","],
124+ ["punctuation", "}"]
125+ ]],
126+ ["keyword", "export"],
127+ ["exports", [
128+ ["punctuation", "{"],
129+ "d ",
130+ ["keyword", "as"],
131+ ["maybe-class-name", "Foo"],
132+ ["punctuation", ","],
133+ " b ",
134+ ["keyword", "as"],
135+ ["maybe-class-name", "Bar"],
136+ ["punctuation", "}"]
137+ ]],
138+ ["keyword", "export"],
139+ ["exports", [
140+ ["punctuation", "{"],
141+ "d ",
142+ ["keyword", "as"],
143+ ["maybe-class-name", "Foo"],
144+ ["punctuation", ","],
145+ " b ",
146+ ["keyword", "as"],
147+ ["maybe-class-name", "Bar"],
148+ ["punctuation", ","],
149+ ["punctuation", "}"]
150+ ]]
151+ ]
Original file line number Diff line number Diff line change 1+ import React from 'react';
2+ import x from "mod";
3+ import * as Foo from "mod";
4+ import {} from "mod";
5+ import {d} from "mod";
6+ import {d,} from "mod";
7+ import {d as Foo, b as Bar} from "mod";
8+ import {d as Foo, b as Bar,} from "mod";
9+ import Foo, { Bar } from "mod";
10+ import Foo, * as Bar from "mod";
11+
12+ import "mod";
13+
14+ ----------------------------------------------------
15+
16+ [
17+ ["keyword", "import"],
18+ ["imports", [
19+ ["maybe-class-name", "React"]
20+ ]],
21+ ["keyword", "from"],
22+ ["string", "'react'"],
23+ ["punctuation", ";"],
24+ ["keyword", "import"],
25+ ["imports", [
26+ "x"
27+ ]],
28+ ["keyword", "from"],
29+ ["string", "\"mod\""],
30+ ["punctuation", ";"],
31+ ["keyword", "import"],
32+ ["imports", [
33+ ["operator", "*"],
34+ ["keyword", "as"],
35+ ["maybe-class-name", "Foo"]
36+ ]],
37+ ["keyword", "from"],
38+ ["string", "\"mod\""],
39+ ["punctuation", ";"],
40+ ["keyword", "import"],
41+ ["imports", [
42+ ["punctuation", "{"],
43+ ["punctuation", "}"]
44+ ]],
45+ ["keyword", "from"],
46+ ["string", "\"mod\""],
47+ ["punctuation", ";"],
48+ ["keyword", "import"],
49+ ["imports", [
50+ ["punctuation", "{"],
51+ "d",
52+ ["punctuation", "}"]
53+ ]],
54+ ["keyword", "from"],
55+ ["string", "\"mod\""],
56+ ["punctuation", ";"],
57+ ["keyword", "import"],
58+ ["imports", [
59+ ["punctuation", "{"],
60+ "d",
61+ ["punctuation", ","],
62+ ["punctuation", "}"]
63+ ]],
64+ ["keyword", "from"],
65+ ["string", "\"mod\""],
66+ ["punctuation", ";"],
67+ ["keyword", "import"],
68+ ["imports", [
69+ ["punctuation", "{"],
70+ "d ",
71+ ["keyword", "as"],
72+ ["maybe-class-name", "Foo"],
73+ ["punctuation", ","],
74+ " b ",
75+ ["keyword", "as"],
76+ ["maybe-class-name", "Bar"],
77+ ["punctuation", "}"]
78+ ]],
79+ ["keyword", "from"],
80+ ["string", "\"mod\""],
81+ ["punctuation", ";"],
82+ ["keyword", "import"],
83+ ["imports", [
84+ ["punctuation", "{"],
85+ "d ",
86+ ["keyword", "as"],
87+ ["maybe-class-name", "Foo"],
88+ ["punctuation", ","],
89+ " b ",
90+ ["keyword", "as"],
91+ ["maybe-class-name", "Bar"],
92+ ["punctuation", ","],
93+ ["punctuation", "}"]
94+ ]],
95+ ["keyword", "from"],
96+ ["string", "\"mod\""],
97+ ["punctuation", ";"],
98+ ["keyword", "import"],
99+ ["imports", [
100+ ["maybe-class-name", "Foo"],
101+ ["punctuation", ","],
102+ ["punctuation", "{"],
103+ ["maybe-class-name", "Bar"],
104+ ["punctuation", "}"]
105+ ]],
106+ ["keyword", "from"],
107+ ["string", "\"mod\""],
108+ ["punctuation", ";"],
109+ ["keyword", "import"],
110+ ["imports", [
111+ ["maybe-class-name", "Foo"],
112+ ["punctuation", ","],
113+ ["operator", "*"],
114+ ["keyword", "as"],
115+ ["maybe-class-name", "Bar"]
116+ ]],
117+ ["keyword", "from"],
118+ ["string", "\"mod\""],
119+ ["punctuation", ";"],
120+
121+ ["keyword", "import"],
122+ ["string", "\"mod\""],
123+ ["punctuation", ";"]
124+ ]
You can’t perform that action at this time.
0 commit comments