@@ -134,24 +134,18 @@ where
134
134
unreachable ! ( )
135
135
}
136
136
} ;
137
- let ( normalized_at_rule_name, name) = if at_keyword_name. 0 . starts_with ( "--" ) {
138
- (
139
- at_keyword_name. 0 . to_ascii_lowercase ( ) ,
140
- AtRuleName :: DashedIdent ( DashedIdent {
141
- span : Span :: new ( span. lo + BytePos ( 1 ) , span. hi , Default :: default ( ) ) ,
142
- value : at_keyword_name. 0 ,
143
- raw : Some ( at_keyword_name. 1 ) ,
144
- } ) ,
145
- )
137
+ let name = if at_keyword_name. 0 . starts_with ( "--" ) {
138
+ AtRuleName :: DashedIdent ( DashedIdent {
139
+ span : Span :: new ( span. lo + BytePos ( 1 ) , span. hi , Default :: default ( ) ) ,
140
+ value : at_keyword_name. 0 ,
141
+ raw : Some ( at_keyword_name. 1 ) ,
142
+ } )
146
143
} else {
147
- (
148
- at_keyword_name. 0 . to_ascii_lowercase ( ) ,
149
- AtRuleName :: Ident ( Ident {
150
- span : Span :: new ( span. lo + BytePos ( 1 ) , span. hi , Default :: default ( ) ) ,
151
- value : at_keyword_name. 0 ,
152
- raw : Some ( at_keyword_name. 1 ) ,
153
- } ) ,
154
- )
144
+ AtRuleName :: Ident ( Ident {
145
+ span : Span :: new ( span. lo + BytePos ( 1 ) , span. hi , Default :: default ( ) ) ,
146
+ value : at_keyword_name. 0 ,
147
+ raw : Some ( at_keyword_name. 1 ) ,
148
+ } )
155
149
} ;
156
150
let mut prelude = vec ! [ ] ;
157
151
let mut at_rule = AtRule {
@@ -181,103 +175,31 @@ where
181
175
tok ! ( ";" ) => {
182
176
self . input . bump ( ) ;
183
177
184
- let list_of_component_values = self . create_locv ( prelude) ;
185
-
186
- at_rule. prelude = match self
187
- . parse_according_to_grammar ( & list_of_component_values, |parser| {
188
- parser. parse_at_rule_prelude ( & normalized_at_rule_name)
189
- } ) {
190
- Ok ( at_rule_prelude) => match at_rule_prelude {
191
- None if normalized_at_rule_name == js_word ! ( "layer" ) => {
192
- self . errors . push ( Error :: new (
193
- span,
194
- ErrorKind :: Expected ( "at least one name" ) ,
195
- ) ) ;
196
-
197
- Some ( Box :: new ( AtRulePrelude :: ListOfComponentValues (
198
- list_of_component_values,
199
- ) ) )
200
- }
201
- _ => at_rule_prelude. map ( Box :: new) ,
202
- } ,
203
- Err ( err) => {
204
- if * err. kind ( ) != ErrorKind :: Ignore {
205
- self . errors . push ( err) ;
206
- }
207
-
208
- if !list_of_component_values. children . is_empty ( ) {
209
- Some ( Box :: new ( AtRulePrelude :: ListOfComponentValues (
210
- list_of_component_values,
211
- ) ) )
212
- } else {
213
- None
214
- }
215
- }
216
- } ;
178
+ at_rule. prelude = Some ( Box :: new ( AtRulePrelude :: ListOfComponentValues (
179
+ self . create_locv ( prelude) ,
180
+ ) ) ) ;
217
181
at_rule. span = span ! ( self , span. lo) ;
218
182
183
+ // Canonicalization against a grammar
184
+ at_rule = self . canonicalize_at_rule_prelude ( at_rule) ?;
185
+
219
186
return Ok ( at_rule) ;
220
187
}
221
188
// <{-token>
222
189
// Consume a simple block and assign it to the at-rule’s block. Return the at-rule.
223
190
tok ! ( "{" ) => {
224
- let mut block = self . parse_as :: < SimpleBlock > ( ) ?;
225
-
226
- let list_of_component_values = self . create_locv ( prelude) ;
227
-
228
- at_rule. prelude = match self
229
- . parse_according_to_grammar ( & list_of_component_values, |parser| {
230
- parser. parse_at_rule_prelude ( & normalized_at_rule_name)
231
- } ) {
232
- Ok ( at_rule_prelude) => match at_rule_prelude {
233
- Some ( AtRulePrelude :: LayerPrelude ( LayerPrelude :: NameList (
234
- name_list,
235
- ) ) ) if name_list. name_list . len ( ) > 1 => {
236
- self . errors . push ( Error :: new (
237
- name_list. span ,
238
- ErrorKind :: Expected ( "only one name" ) ,
239
- ) ) ;
240
-
241
- Some ( Box :: new ( AtRulePrelude :: ListOfComponentValues (
242
- list_of_component_values,
243
- ) ) )
244
- }
245
- _ => at_rule_prelude. map ( Box :: new) ,
246
- } ,
247
- Err ( err) => {
248
- if * err. kind ( ) != ErrorKind :: Ignore {
249
- self . errors . push ( err) ;
250
- }
251
-
252
- if !list_of_component_values. children . is_empty ( ) {
253
- Some ( Box :: new ( AtRulePrelude :: ListOfComponentValues (
254
- list_of_component_values,
255
- ) ) )
256
- } else {
257
- None
258
- }
259
- }
260
- } ;
191
+ let block = self . parse_as :: < SimpleBlock > ( ) ?;
261
192
262
- at_rule. block = match self . parse_according_to_grammar (
263
- & self . create_locv ( block. value . clone ( ) ) ,
264
- |parser| parser. parse_at_rule_block ( & normalized_at_rule_name) ,
265
- ) {
266
- Ok ( block_contents) => {
267
- block. value = block_contents;
268
-
269
- Some ( block)
270
- }
271
- Err ( err) => {
272
- if * err. kind ( ) != ErrorKind :: Ignore {
273
- self . errors . push ( err) ;
274
- }
275
-
276
- Some ( block)
277
- }
278
- } ;
193
+ at_rule. prelude = Some ( Box :: new ( AtRulePrelude :: ListOfComponentValues (
194
+ self . create_locv ( prelude) ,
195
+ ) ) ) ;
196
+ at_rule. block = Some ( block) ;
279
197
at_rule. span = span ! ( self , span. lo) ;
280
198
199
+ // Canonicalization against a grammar
200
+ at_rule = self . canonicalize_at_rule_prelude ( at_rule) ?;
201
+ at_rule = self . canonicalize_at_rule_block ( at_rule) ?;
202
+
281
203
return Ok ( at_rule) ;
282
204
}
283
205
// anything else
@@ -299,50 +221,10 @@ where
299
221
{
300
222
fn parse ( & mut self ) -> PResult < QualifiedRule > {
301
223
// To consume a qualified rule:
302
- let create_prelude =
303
- |p : & mut Parser < I > , list : Vec < ComponentValue > | -> PResult < QualifiedRulePrelude > {
304
- let list_of_component_values = p. create_locv ( list) ;
305
-
306
- if p. ctx . in_keyframes_at_rule {
307
- Ok ( QualifiedRulePrelude :: ListOfComponentValues (
308
- list_of_component_values,
309
- ) )
310
- } else if p. ctx . mixed_with_declarations {
311
- match p. parse_according_to_grammar :: < RelativeSelectorList > (
312
- & list_of_component_values,
313
- |parser| parser. parse ( ) ,
314
- ) {
315
- Ok ( relative_selector_list) => Ok (
316
- QualifiedRulePrelude :: RelativeSelectorList ( relative_selector_list) ,
317
- ) ,
318
- Err ( err) => {
319
- p. errors . push ( err) ;
320
-
321
- Ok ( QualifiedRulePrelude :: ListOfComponentValues (
322
- list_of_component_values,
323
- ) )
324
- }
325
- }
326
- } else {
327
- match p. parse_according_to_grammar :: < SelectorList > (
328
- & list_of_component_values,
329
- |parser| parser. parse ( ) ,
330
- ) {
331
- Ok ( selector_list) => Ok ( QualifiedRulePrelude :: SelectorList ( selector_list) ) ,
332
- Err ( err) => {
333
- p. errors . push ( err) ;
334
224
335
- Ok ( QualifiedRulePrelude :: ListOfComponentValues (
336
- list_of_component_values,
337
- ) )
338
- }
339
- }
340
- }
341
- } ;
342
-
343
- let span = self . input . cur_span ( ) ;
344
225
// Create a new qualified rule with its prelude initially set to an empty list,
345
226
// and its value initially set to nothing.
227
+ let span = self . input . cur_span ( ) ;
346
228
let mut prelude = vec ! [ ] ;
347
229
348
230
// Repeatedly consume the next input token:
@@ -375,30 +257,20 @@ where
375
257
// Consume a simple block and assign it to the qualified rule’s block. Return the
376
258
// qualified rule.
377
259
tok ! ( "{" ) => {
378
- let mut block = self . parse_as :: < SimpleBlock > ( ) ?;
379
-
380
- block. value = match self . ctx . block_contents_grammar {
381
- BlockContentsGrammar :: DeclarationList => self
382
- . parse_according_to_grammar ( & self . create_locv ( block. value ) , |parser| {
383
- parser. parse_as :: < Vec < DeclarationOrAtRule > > ( )
384
- } ) ?
385
- . into_iter ( )
386
- . map ( ComponentValue :: DeclarationOrAtRule )
387
- . collect ( ) ,
388
- _ => self
389
- . parse_according_to_grammar ( & self . create_locv ( block. value ) , |parser| {
390
- parser. parse_as :: < Vec < StyleBlock > > ( )
391
- } ) ?
392
- . into_iter ( )
393
- . map ( ComponentValue :: StyleBlock )
394
- . collect ( ) ,
395
- } ;
396
-
397
- return Ok ( QualifiedRule {
260
+ let block = self . parse_as :: < SimpleBlock > ( ) ?;
261
+ let mut qualified_rule = QualifiedRule {
398
262
span : span ! ( self , span. lo) ,
399
- prelude : create_prelude ( self , prelude) ?,
263
+ prelude : QualifiedRulePrelude :: ListOfComponentValues (
264
+ self . create_locv ( prelude) ,
265
+ ) ,
400
266
block,
401
- } ) ;
267
+ } ;
268
+
269
+ // Canonicalization against a grammar
270
+ qualified_rule = self . canonicalize_qualified_rule_prelude ( qualified_rule) ?;
271
+ qualified_rule = self . canonicalize_qualified_rule_block ( qualified_rule) ?;
272
+
273
+ return Ok ( qualified_rule) ;
402
274
}
403
275
// Reconsume the current input token. Consume a component value. Append the returned
404
276
// value to the qualified rule’s prelude.
@@ -458,12 +330,7 @@ where
458
330
// Reconsume the current input token. Consume an at-rule, and append the result to
459
331
// rules.
460
332
tok ! ( "@" ) => {
461
- let at_rule = self
462
- . with_ctx ( Ctx {
463
- block_contents_grammar : BlockContentsGrammar :: StyleBlock ,
464
- ..self . ctx
465
- } )
466
- . parse_as :: < AtRule > ( ) ?;
333
+ let at_rule = self . parse ( ) ?;
467
334
468
335
rules. push ( StyleBlock :: AtRule ( Box :: new ( at_rule) ) ) ;
469
336
}
@@ -880,32 +747,8 @@ where
880
747
return Ok ( declaration) ;
881
748
}
882
749
883
- // Grammar parsing
884
- let list_of_component_values = self . create_locv ( declaration. value ) ;
885
-
886
- declaration. value =
887
- match self . parse_according_to_grammar ( & list_of_component_values, |parser| {
888
- let mut values = vec ! [ ] ;
889
-
890
- loop {
891
- if is ! ( parser, EOF ) {
892
- break ;
893
- }
894
-
895
- values. push ( parser. parse_generic_value ( ) ?) ;
896
- }
897
-
898
- Ok ( values)
899
- } ) {
900
- Ok ( values) => values,
901
- Err ( err) => {
902
- if * err. kind ( ) != ErrorKind :: Ignore {
903
- self . errors . push ( err) ;
904
- }
905
-
906
- list_of_component_values. children
907
- }
908
- } ;
750
+ // Canonicalization against a grammar
751
+ declaration = self . canonicalize_declaration_value ( declaration) ?;
909
752
910
753
// 8. Return the declaration.
911
754
Ok ( declaration)
@@ -1055,9 +898,8 @@ where
1055
898
unreachable ! ( )
1056
899
}
1057
900
} ;
1058
- let function_name = & * ident. 0 . to_ascii_lowercase ( ) ;
1059
901
let name = Ident {
1060
- span : swc_common :: Span :: new ( span. lo , span. hi - BytePos ( 1 ) , Default :: default ( ) ) ,
902
+ span : Span :: new ( span. lo , span. hi - BytePos ( 1 ) , Default :: default ( ) ) ,
1061
903
value : ident. 0 ,
1062
904
raw : Some ( ident. 1 ) ,
1063
905
} ;
@@ -1101,26 +943,8 @@ where
1101
943
1102
944
function. span = span ! ( self , span. lo) ;
1103
945
1104
- // Grammar parsing
1105
- match self . ctx . block_contents_grammar {
1106
- BlockContentsGrammar :: DeclarationList => { }
1107
- _ => {
1108
- let locv = self . create_locv ( function. value ) ;
1109
-
1110
- function. value = match self . parse_according_to_grammar ( & locv, |parser| {
1111
- parser. parse_function_values ( function_name)
1112
- } ) {
1113
- Ok ( values) => values,
1114
- Err ( err) => {
1115
- if * err. kind ( ) != ErrorKind :: Ignore {
1116
- self . errors . push ( err) ;
1117
- }
1118
-
1119
- locv. children
1120
- }
1121
- } ;
1122
- }
1123
- }
946
+ // Canonicalization against a grammar
947
+ function = self . canonicalize_function_value ( function) ?;
1124
948
1125
949
return Ok ( function) ;
1126
950
}
1 commit comments
github-actions[bot] commentedon Nov 15, 2022
Benchmark
es/full/bugs-1
343131
ns/iter (± 18927
)356010
ns/iter (± 28302
)0.96
es/full/minify/libraries/antd
1879029520
ns/iter (± 86154105
)1868954143
ns/iter (± 41828480
)1.01
es/full/minify/libraries/d3
414102995
ns/iter (± 17005550
)427267789
ns/iter (± 16138148
)0.97
es/full/minify/libraries/echarts
1577618030
ns/iter (± 58450498
)1577385149
ns/iter (± 22702097
)1.00
es/full/minify/libraries/jquery
102708379
ns/iter (± 4908626
)106672079
ns/iter (± 2651444
)0.96
es/full/minify/libraries/lodash
125489448
ns/iter (± 6342439
)131443744
ns/iter (± 5431446
)0.95
es/full/minify/libraries/moment
59496706
ns/iter (± 2012974
)62479974
ns/iter (± 2256311
)0.95
es/full/minify/libraries/react
19967860
ns/iter (± 1038082
)22295733
ns/iter (± 2495811
)0.90
es/full/minify/libraries/terser
337947003
ns/iter (± 54535627
)341305748
ns/iter (± 37992550
)0.99
es/full/minify/libraries/three
573368575
ns/iter (± 33838779
)581803883
ns/iter (± 24392579
)0.99
es/full/minify/libraries/typescript
3503261209
ns/iter (± 124237777
)3324414259
ns/iter (± 141363385
)1.05
es/full/minify/libraries/victory
864893126
ns/iter (± 39416137
)840069254
ns/iter (± 30542715
)1.03
es/full/minify/libraries/vue
171950018
ns/iter (± 10840345
)163713162
ns/iter (± 9059088
)1.05
es/full/codegen/es3
35524
ns/iter (± 2234
)40217
ns/iter (± 6880
)0.88
es/full/codegen/es5
35047
ns/iter (± 3099
)35006
ns/iter (± 5217
)1.00
es/full/codegen/es2015
34463
ns/iter (± 1634
)33851
ns/iter (± 1235
)1.02
es/full/codegen/es2016
34603
ns/iter (± 1133
)33814
ns/iter (± 1497
)1.02
es/full/codegen/es2017
34599
ns/iter (± 1274
)34624
ns/iter (± 2010
)1.00
es/full/codegen/es2018
34350
ns/iter (± 1591
)34166
ns/iter (± 1046
)1.01
es/full/codegen/es2019
34720
ns/iter (± 2050
)33853
ns/iter (± 1048
)1.03
es/full/codegen/es2020
34496
ns/iter (± 1178
)34083
ns/iter (± 2527
)1.01
es/full/all/es3
200853664
ns/iter (± 13412938
)239787286
ns/iter (± 21209274
)0.84
es/full/all/es5
234003167
ns/iter (± 30838241
)223411060
ns/iter (± 23802659
)1.05
es/full/all/es2015
181154661
ns/iter (± 21853824
)170529182
ns/iter (± 20469715
)1.06
es/full/all/es2016
161489277
ns/iter (± 26404058
)159386307
ns/iter (± 14381462
)1.01
es/full/all/es2017
161681927
ns/iter (± 8902858
)164722662
ns/iter (± 52563112
)0.98
es/full/all/es2018
158742089
ns/iter (± 9826764
)159779349
ns/iter (± 21667518
)0.99
es/full/all/es2019
174600328
ns/iter (± 11801874
)166757541
ns/iter (± 17136334
)1.05
es/full/all/es2020
155677061
ns/iter (± 9995349
)159267746
ns/iter (± 21235222
)0.98
es/full/parser
756093
ns/iter (± 52006
)765942
ns/iter (± 87392
)0.99
es/full/base/fixer
28013
ns/iter (± 2796
)27953
ns/iter (± 1146
)1.00
es/full/base/resolver_and_hygiene
97198
ns/iter (± 4485
)94553
ns/iter (± 4436
)1.03
serialization of ast node
220
ns/iter (± 7
)232
ns/iter (± 12
)0.95
serialization of serde
224
ns/iter (± 5
)226
ns/iter (± 6
)0.99
This comment was automatically generated by workflow using github-action-benchmark.