Skip to content

Commit 8304dbc

Browse files
committed
Minor things
1 parent cb81397 commit 8304dbc

File tree

6 files changed

+20
-16
lines changed

6 files changed

+20
-16
lines changed

__tests__/style.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,8 +469,9 @@ describe('<whole-value>', () => {
469469
test('valid', () => {
470470
const style = createStyleBlock()
471471
const valid = [
472+
// Resolved at parse time
473+
['first-valid(1)', '1', 'opacity'],
472474
// Serialize the list of tokens
473-
[' /**/ first-valid( /**/ 1e0 /**/ ', '1', 'opacity'],
474475
[' /**/ mix( 0, 1, /**/ 1e0 /**/ ', 'mix(0, 1, 1)', 'opacity'],
475476
[' /**/ toggle( /**/ 1e0 /**/ ', 'toggle(1)', 'opacity'],
476477
// Nested inside itself

__tests__/stylesheet.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ function createStyleSheet(rules = '', properties = {}) {
6161
*
6262
* This abstraction is not great but probably the best way to avoid increasing
6363
* code complexity in tests, until first-valid() can be replaced with another
64-
* <whole-value> substitution that do not require resolved at parse time.
64+
* <whole-value> substitution that do not require to be resolved at parse time.
6565
*/
6666
function normalizeText(text) {
6767
return text
@@ -1069,7 +1069,7 @@ describe('CSS grammar - syntax', () => {
10691069
})
10701070
test('nested - declaration with a value containing a bad token', () => {
10711071
// It is always invalid... except with forgiving grammar?
1072-
const { cssRules: [nested] } = createStyleSheet(`
1072+
const styleSheet = createStyleSheet(`
10731073
style {
10741074
color: var(--custom) "\n;
10751075
color: var(--custom) url(bad .url);
@@ -1080,46 +1080,46 @@ describe('CSS grammar - syntax', () => {
10801080
style {}
10811081
}
10821082
`)
1083-
expect(nested.cssText).toBe('style { & style {} }')
1083+
expect(styleSheet.cssRules[0].cssText).toBe('style { & style {} }')
10841084
})
10851085
test('nested - declaration not for a custom property with a value containing a positioned {}-block', () => {
10861086
// It is always consumed as a rule
1087-
const { cssRules: [nested] } = createStyleSheet(`
1087+
const styleSheet = createStyleSheet(`
10881088
style {
10891089
color: {} var(--custom);
10901090
color:var(--custom) {}
10911091
color: ] {}
10921092
style:hover {}
10931093
}
10941094
`)
1095-
expect(nested.cssText).toBe('style { & style:hover {} }')
1095+
expect(styleSheet.cssRules[0].cssText).toBe('style { & style:hover {} }')
10961096
})
10971097
test('nested - declaration for a custom property with a value containing a positioned {}-block', () => {
10981098
// It is never consumed as a qualified rule in a nested context
1099-
const { cssRules: [nested] } = createStyleSheet(`
1099+
const styleSheet = createStyleSheet(`
11001100
style {
11011101
--custom-1: {} 1;
11021102
--custom-2: 1 {};
11031103
--custom-3: ] {}
11041104
style:hover {}
11051105
}
11061106
`)
1107-
expect(nested.cssText).toBe('style { --custom-1: {} 1; --custom-2: 1 {}; }')
1107+
expect(styleSheet.cssRules[0].cssText).toBe('style { --custom-1: {} 1; --custom-2: 1 {}; }')
11081108
})
11091109
})
11101110

11111111
describe('CSS grammar - semantic', () => {
11121112
// Style sheet contents
11131113
test('top-level - invalid contents', () => {
1114-
const { cssRules } = createStyleSheet(`
1114+
const styleSheet = createStyleSheet(`
11151115
@charset "utf-8";
11161116
@namespace svg "http://www.w3.org/2000/svg" {}
11171117
@media;
11181118
@annotation {}
11191119
@top-left {}
11201120
0% {}
11211121
`)
1122-
expect(cssRules).toHaveLength(0)
1122+
expect(styleSheet.cssRules).toHaveLength(0)
11231123
})
11241124
test('top-level - opening and ending HTML comment tokens', () => {
11251125

__tests__/value.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -779,10 +779,10 @@ describe('functions', () => {
779779
})
780780
test('valid', () => {
781781
const valid = [
782-
// Unclosed (parse error)
783-
['fn()', 'fn(', 'fn()'],
784782
// Case-insensitive name
785783
['fn(a)', 'FN(a)', 'fn(a)'],
784+
// Unclosed (parse error)
785+
['fn()', 'fn(', 'fn()'],
786786
// Comma-containing production
787787
['fn([<declaration-value>?]#)', 'fn({}, , { a }, { , }, {{}})', 'fn(,, a, {,}, {{}})'],
788788
['fn(<declaration-value>?, a)', 'fn(, a)'],

doc/parse/parser.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ An **ambiguity** exists when there are multiple derivations for the same input.
5757

5858
A canonical example to illustrate a parsing ambiguity is the grammar of math operations, which involves associativity and precedence rules. The priorities associated with these rules are important because the (semantic) result could be different without them.
5959

60-
As in math operations, left associativity is usually expected for parsing programming languages: the parser must read the input from left to right: `1 - 2 + 3` must be interpreted to `2` instead of `4`. But to interpret `1 + 2 * 3` to `7` instead of `9`, precedence rules must be hard-coded with a more complex value definition than `<calc-value> [['+' | '-' | '*' | '/'] <calc-value>]*`.
60+
As in math operations, left associativity is usually expected for parsing programming languages: the parser must read the input from left to right: `1 - 2 + 3` must be interpreted to `2` instead of `4`. But to interpret `1 + 2 * 3` to `7` instead of `9`, precedence rules must be encoded with a more complex value definition than `<calc-value> [['+' | '-' | '*' | '/'] <calc-value>]*`.
6161

6262
For grammars that remain ambiguous, a priority must be decided, either ahead of time (statically), with the first, last, or longest match priority, or at parse time (dynamically), depending on the context.
6363

lib/parse/grammar.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,10 @@ function matchSimpleBlock(block, node, parser) {
237237
const { associatedToken, types, value } = block
238238
const { context, definition, input } = node
239239
if (types[0] === '<simple-block>' && associatedToken === definition.associatedToken) {
240-
const match = parser.parseCSSValue(new Stream(value, input.source), definition.value, context)
240+
const match = parser.parseCSSValue(
241+
new Stream(value, input.source),
242+
definition.value,
243+
{ ...context, block: context })
241244
if (match instanceof SyntaxError) {
242245
return match
243246
}

lib/parse/postprocess.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,8 +422,8 @@ function postParseDashedIdent(identifier) {
422422
*
423423
* It aborts parsing when the head uses an invalid <dashed-ident> name.
424424
*/
425-
function postParseDashedFunctionHead(head, node, { parseCSSGrammar }) {
426-
if (parseCSSGrammar(head[0].name, '<dashed-ident>', node.context)) {
425+
function postParseDashedFunctionHead(head, node, parser) {
426+
if (parser.parseCSSGrammar(head[0].name, '<dashed-ident>', node.context)) {
427427
return head
428428
}
429429
return error(node)

0 commit comments

Comments
 (0)