Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tokenIndex to SymbolNode #2796

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/expression/node/AccessorNode.js
Expand Up @@ -136,7 +136,9 @@ export const createAccessorNode = /* #__PURE__ */ factory(name, dependencies, ({
* @return {AccessorNode}
*/
clone () {
return new AccessorNode(this.object, this.index)
const cloned = new AccessorNode(this.object, this.index)
cloned.sources = this.sources
return cloned
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/expression/node/ArrayNode.js
Expand Up @@ -94,7 +94,9 @@ export const createArrayNode = /* #__PURE__ */ factory(name, dependencies, ({ No
* @return {ArrayNode}
*/
clone () {
return new ArrayNode(this.items.slice(0))
const cloned = new ArrayNode(this.items.slice(0))
cloned.sources = this.sources
return cloned
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/expression/node/AssignmentNode.js
Expand Up @@ -231,7 +231,9 @@ export const createAssignmentNode = /* #__PURE__ */ factory(name, dependencies,
* @return {AssignmentNode}
*/
clone () {
return new AssignmentNode(this.object, this.index, this.value)
const cloned = new AssignmentNode(this.object, this.index, this.value)
cloned.sources = this.sources
return cloned
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/expression/node/BlockNode.js
Expand Up @@ -119,7 +119,9 @@ export const createBlockNode = /* #__PURE__ */ factory(name, dependencies, ({ Re
}
})

return new BlockNode(blocks)
const cloned = new BlockNode(blocks)
cloned.sources = this.sources
return cloned
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/expression/node/ConditionalNode.js
Expand Up @@ -121,7 +121,9 @@ export const createConditionalNode = /* #__PURE__ */ factory(name, dependencies,
* @return {ConditionalNode}
*/
clone () {
return new ConditionalNode(this.condition, this.trueExpr, this.falseExpr)
const cloned = new ConditionalNode(this.condition, this.trueExpr, this.falseExpr)
cloned.sources = this.sources
return cloned
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/expression/node/ConstantNode.js
Expand Up @@ -75,7 +75,9 @@ export const createConstantNode = /* #__PURE__ */ factory(name, dependencies, ({
* @return {ConstantNode}
*/
clone () {
return new ConstantNode(this.value)
const cloned = new ConstantNode(this.value)
cloned.sources = this.sources
return cloned
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/expression/node/FunctionAssignmentNode.js
Expand Up @@ -149,8 +149,10 @@ export const createFunctionAssignmentNode = /* #__PURE__ */ factory(name, depend
* @return {FunctionAssignmentNode}
*/
clone () {
return new FunctionAssignmentNode(
const cloned = new FunctionAssignmentNode(
this.name, this.params.slice(0), this.expr)
cloned.sources = this.sources
return cloned
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/expression/node/FunctionNode.js
Expand Up @@ -310,7 +310,9 @@ export const createFunctionNode = /* #__PURE__ */ factory(name, dependencies, ({
* @return {FunctionNode}
*/
clone () {
return new FunctionNode(this.fn, this.args.slice(0))
const cloned = new FunctionNode(this.fn, this.args.slice(0))
cloned.sources = this.sources
return cloned
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/expression/node/IndexNode.js
Expand Up @@ -141,7 +141,9 @@ export const createIndexNode = /* #__PURE__ */ factory(name, dependencies, ({ No
* @return {IndexNode}
*/
clone () {
return new IndexNode(this.dimensions.slice(0), this.dotNotation)
const cloned = new IndexNode(this.dimensions.slice(0), this.dotNotation)
cloned.sources = this.sources
return cloned
}

/**
Expand Down
11 changes: 11 additions & 0 deletions src/expression/node/Node.js
Expand Up @@ -23,6 +23,8 @@ export const createNode = /* #__PURE__ */ factory(name, dependencies, ({ mathWit
}

class Node {
sources = []

get type () { return 'Node' }
get isNode () { return true }

Expand Down Expand Up @@ -204,6 +206,15 @@ export const createNode = /* #__PURE__ */ factory(name, dependencies, ({ mathWit
throw new Error('Cannot clone a Node interface')
}

/**
* Set the source indices mapping this node back to its
* location in the original source string
* @param {SourceMapping[]} sources - the data mapping this node back to its source string
*/
setSources (sources) {
this.sources = sources
}

/**
* Create a deep clone of this node
* @return {Node}
Expand Down
4 changes: 3 additions & 1 deletion src/expression/node/ObjectNode.js
Expand Up @@ -121,7 +121,9 @@ export const createObjectNode = /* #__PURE__ */ factory(name, dependencies, ({ N
properties[key] = this.properties[key]
}
}
return new ObjectNode(properties)
const cloned = new ObjectNode(properties)
cloned.sources = this.sources
return cloned
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/expression/node/OperatorNode.js
Expand Up @@ -356,8 +356,10 @@ export const createOperatorNode = /* #__PURE__ */ factory(name, dependencies, ({
* @return {OperatorNode}
*/
clone () {
return new OperatorNode(
const cloned = new OperatorNode(
this.op, this.fn, this.args.slice(0), this.implicit, this.isPercentage)
cloned.sources = this.sources
return cloned
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/expression/node/ParenthesisNode.js
Expand Up @@ -79,7 +79,9 @@ export const createParenthesisNode = /* #__PURE__ */ factory(name, dependencies,
* @return {ParenthesisNode}
*/
clone () {
return new ParenthesisNode(this.content)
const cloned = new ParenthesisNode(this.content)
cloned.sources = this.sources
return cloned
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/expression/node/RangeNode.js
Expand Up @@ -146,7 +146,9 @@ export const createRangeNode = /* #__PURE__ */ factory(name, dependencies, ({ No
* @return {RangeNode}
*/
clone () {
return new RangeNode(this.start, this.end, this.step && this.step)
const cloned = new RangeNode(this.start, this.end, this.step && this.step)
cloned.sources = this.sources
return cloned
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/expression/node/RelationalNode.js
Expand Up @@ -109,7 +109,9 @@ export const createRelationalNode = /* #__PURE__ */ factory(name, dependencies,
* @return {RelationalNode}
*/
clone () {
return new RelationalNode(this.conditionals, this.params)
const cloned = new RelationalNode(this.conditionals, this.params)
cloned.sources = this.sources
return cloned
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/expression/node/SymbolNode.js
Expand Up @@ -114,7 +114,9 @@ export const createSymbolNode = /* #__PURE__ */ factory(name, dependencies, ({ m
* @return {SymbolNode}
*/
clone () {
return new SymbolNode(this.name)
const cloned = new SymbolNode(this.name)
cloned.sources = this.sources
return cloned
}

/**
Expand Down