Skip to content

Commit

Permalink
fix: All nodes have a source property, not just Root
Browse files Browse the repository at this point in the history
  • Loading branch information
mischnic committed Dec 8, 2020
1 parent ce355c3 commit 7454de3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
26 changes: 13 additions & 13 deletions lib/fromJSON.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@ function fromJSON (json) {
if (json.nodes) {
defaults.nodes = json.nodes.map(i => fromJSON(i))
}
if (json.type === 'root') {
if (defaults.source) {
defaults.source = { ...defaults.source }
if (defaults.source.input) {
defaults.source.input = {
...defaults.source.input,
__proto__: Input.prototype
}
if (defaults.source.input.map) {
defaults.source.input.map = {
...defaults.source.input.map,
__proto__: PreviousMap.prototype
}
if (defaults.source) {
defaults.source = { ...defaults.source }
if (defaults.source.input) {
defaults.source.input = {
...defaults.source.input,
__proto__: Input.prototype
}
if (defaults.source.input.map) {
defaults.source.input.map = {
...defaults.source.input.map,
__proto__: PreviousMap.prototype
}
}
}
}
if (json.type === 'root') {
return new Root(defaults)
} else if (json.type === 'decl') {
return new Declaration(defaults)
Expand Down
2 changes: 1 addition & 1 deletion lib/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ class Node {
})
} else if (typeof value === 'object' && value.toJSON) {
fixed[name] = value.toJSON()
} else if (this.type === 'root' && name === 'source') {
} else if (name === 'source') {
fixed[name] = {
input: value.input.toJSON(),
start: value.start
Expand Down

0 comments on commit 7454de3

Please sign in to comment.