Skip to content

Commit

Permalink
perf: code golf .loc and .offset
Browse files Browse the repository at this point in the history
  • Loading branch information
Bart Veneman committed Nov 21, 2023
1 parent 9d7fc0a commit bab4fba
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
10 changes: 6 additions & 4 deletions src/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ export class Collection {
*/
push(item, node_location) {
let index = this._total
let start = node_location.start
let start_offset = start.offset

this._node_lines[index] = node_location.start.line
this._node_columns[index] = node_location.start.column
this._node_offsets[index] = node_location.start.offset
this._node_lengths[index] = node_location.end.offset - node_location.start.offset
this._node_lines[index] = start.line
this._node_columns[index] = start.column
this._node_offsets[index] = start_offset
this._node_lengths[index] = node_location.end.offset - start_offset

if (this._items.has(item)) {
/** @type number[] */
Expand Down
13 changes: 7 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ export function analyze(css, options = {}) {
}

function stringifyNodePlain(node) {
return css.substring(node.loc.start.offset, node.loc.end.offset)
let loc = node.loc
return css.substring(loc.start.offset, loc.end.offset)
}

// Stylesheet
Expand Down Expand Up @@ -566,15 +567,15 @@ export function analyze(css, options = {}) {
}
}

let { property } = node
let { property, loc: { start } } = node
let propertyLoc = {
start: {
line: node.loc.start.line,
column: node.loc.start.column,
offset: node.loc.start.offset
line: start.line,
column: start.column,
offset: start.offset
},
end: {
offset: node.loc.start.offset + property.length
offset: start.offset + property.length
}
}

Expand Down

0 comments on commit bab4fba

Please sign in to comment.