Skip to content

Commit 813d695

Browse files
committed
update parser to 0.8.0, fix location.end
1 parent 34041cb commit 813d695

File tree

6 files changed

+60
-59
lines changed

6 files changed

+60
-59
lines changed

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,6 @@
5656
"singleQuote": true
5757
},
5858
"dependencies": {
59-
"@projectwallace/css-parser": "^0.6.3"
59+
"@projectwallace/css-parser": "^0.8.0"
6060
}
6161
}

src/index.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { TreeNode } from './TreeNode.js'
2-
import { NODE_AT_RULE, NODE_PRELUDE_IMPORT_LAYER, NODE_PRELUDE_LAYER_NAME, parse, traverse } from '@projectwallace/css-parser'
2+
import { AT_RULE, LAYER_NAME, parse, traverse } from '@projectwallace/css-parser'
33

44
/** @param {string} name */
55
function get_layer_names(name) {
@@ -11,7 +11,8 @@ function create_location(node) {
1111
return {
1212
line: node.line,
1313
column: node.column,
14-
start: node.offset,
14+
start: node.start,
15+
end: node.end,
1516
}
1617
}
1718

@@ -30,7 +31,7 @@ export function layer_tree_from_ast(ast) {
3031

3132
traverse(ast, {
3233
enter(node) {
33-
if (node.type !== NODE_AT_RULE) return
34+
if (node.type !== AT_RULE) return
3435

3536
if (node.name === 'layer') {
3637
if (node.prelude !== null) {
@@ -52,7 +53,7 @@ export function layer_tree_from_ast(ast) {
5253
}
5354
} else {
5455
for (let child of node.children) {
55-
if (child.type === NODE_PRELUDE_LAYER_NAME) {
56+
if (child.type === LAYER_NAME) {
5657
root.add_child(current_stack, child.text, create_location(node))
5758
current_stack.push(child.text)
5859
}
@@ -67,7 +68,7 @@ export function layer_tree_from_ast(ast) {
6768
// @import url("foo.css") layer(test);
6869
// OR
6970
// @import url("foo.css") layer(test.nested);
70-
let layerNode = node.children.find((child) => child.type === NODE_PRELUDE_IMPORT_LAYER)
71+
let layerNode = node.children.find((child) => child.type === LAYER_NAME)
7172
if (layerNode) {
7273
if (layerNode.name.trim()) {
7374
for (let layer_name of get_layer_names(layerNode.name)) {
@@ -83,13 +84,13 @@ export function layer_tree_from_ast(ast) {
8384
}
8485
},
8586
leave(node) {
86-
if (node.type !== NODE_AT_RULE) return
87+
if (node.type !== AT_RULE) return
8788

8889
if (node.name === 'layer') {
8990
if (node.has_prelude) {
90-
let has_block = node.has_children && node.children.some((c) => c.type !== NODE_PRELUDE_LAYER_NAME)
91+
let has_block = node.has_children && node.children.some((c) => c.type !== LAYER_NAME)
9192
if (has_block) {
92-
let name = node.children.find((child) => child.type === NODE_PRELUDE_LAYER_NAME)
93+
let name = node.children.find((child) => child.type === LAYER_NAME)
9394
if (name) {
9495
let layer_names = get_layer_names(name.text)
9596
for (let i = 0; i < layer_names.length; i++) {

test/global.spec.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,29 +26,29 @@ test('mixed imports and layers', () => {
2626
{
2727
name: '__anonymous-1__',
2828
is_anonymous: true,
29-
locations: [{ line: 2, column: 3, start: 3 }],
29+
locations: [{ line: 2, column: 3, start: 3, end: 33 }],
3030
children: [],
3131
},
3232
{
3333
name: 'test',
3434
is_anonymous: false,
35-
locations: [{ line: 3, column: 3, start: 36 }],
35+
locations: [{ line: 3, column: 3, start: 36, end: 72 }],
3636
children: [],
3737
},
3838
{
3939
name: 'anotherTest',
4040
is_anonymous: false,
41-
locations: [{ line: 4, column: 3, start: 75 }],
41+
locations: [{ line: 4, column: 3, start: 75, end: 148 }],
4242
children: [
4343
{
4444
name: 'moreTest',
4545
is_anonymous: false,
46-
locations: [{ line: 5, column: 4, start: 99 }],
46+
locations: [{ line: 5, column: 4, start: 99, end: 144 }],
4747
children: [
4848
{
4949
name: 'deepTest',
5050
is_anonymous: false,
51-
locations: [{ line: 6, column: 5, start: 121 }],
51+
locations: [{ line: 6, column: 5, start: 121, end: 139 }],
5252
children: [],
5353
},
5454
],
@@ -58,7 +58,7 @@ test('mixed imports and layers', () => {
5858
{
5959
name: '__anonymous-2__',
6060
is_anonymous: true,
61-
locations: [{ line: 10, column: 3, start: 176 }],
61+
locations: [{ line: 10, column: 3, start: 176, end: 185 }],
6262
children: [],
6363
},
6464
]
@@ -76,70 +76,70 @@ test('the fokus.dev boilerplate', () => {
7676
{
7777
name: 'core',
7878
is_anonymous: false,
79-
locations: [{ line: 2, column: 3, start: 3 }],
79+
locations: [{ line: 2, column: 3, start: 3, end: 49 }],
8080
children: [
8181
{
8282
name: 'reset',
8383
is_anonymous: false,
84-
locations: [{ line: 3, column: 3, start: 52 }],
84+
locations: [{ line: 3, column: 3, start: 52, end: 94 }],
8585
children: [],
8686
},
8787
{
8888
name: 'tokens',
8989
is_anonymous: false,
90-
locations: [{ line: 3, column: 3, start: 52 }],
90+
locations: [{ line: 3, column: 3, start: 52, end: 94 }],
9191
children: [],
9292
},
9393
{
9494
name: 'base',
9595
is_anonymous: false,
96-
locations: [{ line: 3, column: 3, start: 52 }],
96+
locations: [{ line: 3, column: 3, start: 52, end: 94 }],
9797
children: [],
9898
},
9999
],
100100
},
101101
{
102102
name: 'third-party',
103103
is_anonymous: false,
104-
locations: [{ line: 2, column: 3, start: 3 }],
104+
locations: [{ line: 2, column: 3, start: 3, end: 49 }],
105105
children: [
106106
{
107107
name: 'imports',
108108
is_anonymous: false,
109-
locations: [{ line: 4, column: 3, start: 97 }],
109+
locations: [{ line: 4, column: 3, start: 97, end: 147 }],
110110
children: [],
111111
},
112112
{
113113
name: 'overrides',
114114
is_anonymous: false,
115-
locations: [{ line: 4, column: 3, start: 97 }],
115+
locations: [{ line: 4, column: 3, start: 97, end: 147 }],
116116
children: [],
117117
},
118118
],
119119
},
120120
{
121121
name: 'components',
122122
is_anonymous: false,
123-
locations: [{ line: 2, column: 3, start: 3 }],
123+
locations: [{ line: 2, column: 3, start: 3, end: 49 }],
124124
children: [
125125
{
126126
name: 'base',
127127
is_anonymous: false,
128-
locations: [{ line: 5, column: 3, start: 150 }],
128+
locations: [{ line: 5, column: 3, start: 150, end: 196 }],
129129
children: [],
130130
},
131131
{
132132
name: 'variations',
133133
is_anonymous: false,
134-
locations: [{ line: 5, column: 3, start: 150 }],
134+
locations: [{ line: 5, column: 3, start: 150, end: 196 }],
135135
children: [],
136136
},
137137
],
138138
},
139139
{
140140
name: 'utility',
141141
is_anonymous: false,
142-
locations: [{ line: 2, column: 3, start: 3 }],
142+
locations: [{ line: 2, column: 3, start: 3, end: 49 }],
143143
children: [],
144144
},
145145
]

test/import.spec.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ test('@import url() layer', () => {
88
{
99
name: '__anonymous-1__',
1010
is_anonymous: true,
11-
locations: [{ line: 1, column: 1, start: 0 }],
11+
locations: [{ line: 1, column: 1, start: 0, end: 29 }],
1212
children: [],
1313
},
1414
]
@@ -21,7 +21,7 @@ test('@import url() LAYER', () => {
2121
{
2222
name: '__anonymous-1__',
2323
is_anonymous: true,
24-
locations: [{ line: 1, column: 1, start: 0 }],
24+
locations: [{ line: 1, column: 1, start: 0, end: 29 }],
2525
children: [],
2626
},
2727
]
@@ -34,7 +34,7 @@ test('@import url() layer(named)', () => {
3434
{
3535
name: 'named',
3636
is_anonymous: false,
37-
locations: [{ line: 1, column: 1, start: 0 }],
37+
locations: [{ line: 1, column: 1, start: 0, end: 36 }],
3838
children: [],
3939
},
4040
]
@@ -47,7 +47,7 @@ test('@import url() LAYER(named)', () => {
4747
{
4848
name: 'named',
4949
is_anonymous: false,
50-
locations: [{ line: 1, column: 1, start: 0 }],
50+
locations: [{ line: 1, column: 1, start: 0, end: 36 }],
5151
children: [],
5252
},
5353
]
@@ -60,12 +60,12 @@ test('@import url() layer(named.nested)', () => {
6060
{
6161
name: 'named',
6262
is_anonymous: false,
63-
locations: [{ line: 1, column: 1, start: 0 }],
63+
locations: [{ line: 1, column: 1, start: 0, end: 43 }],
6464
children: [
6565
{
6666
name: 'nested',
6767
is_anonymous: false,
68-
locations: [{ line: 1, column: 1, start: 0 }],
68+
locations: [{ line: 1, column: 1, start: 0, end: 43 }],
6969
children: [],
7070
},
7171
],
@@ -80,12 +80,12 @@ test('@import url() layer(named.nested )', () => {
8080
{
8181
name: 'named',
8282
is_anonymous: false,
83-
locations: [{ line: 1, column: 1, start: 0 }],
83+
locations: [{ line: 1, column: 1, start: 0, end: 48 }],
8484
children: [
8585
{
8686
name: 'nested',
8787
is_anonymous: false,
88-
locations: [{ line: 1, column: 1, start: 0 }],
88+
locations: [{ line: 1, column: 1, start: 0, end: 48 }],
8989
children: [],
9090
},
9191
],
@@ -100,12 +100,12 @@ test('@import url() layer(/* test */named.nested )', () => {
100100
{
101101
name: 'named',
102102
is_anonymous: false,
103-
locations: [{ line: 1, column: 1, start: 0 }],
103+
locations: [{ line: 1, column: 1, start: 0, end: 58 }],
104104
children: [
105105
{
106106
name: 'nested',
107107
is_anonymous: false,
108-
locations: [{ line: 1, column: 1, start: 0 }],
108+
locations: [{ line: 1, column: 1, start: 0, end: 58 }],
109109
children: [],
110110
},
111111
],

0 commit comments

Comments
 (0)