Extends
- Adapter
Methods
childNodeRange(node, childName) → {Object}
Get the source range of child node.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
node |
Node
|
The node. |
childName |
string
|
The name to find child node. |
Throws:
-
if we can't get the range.
- Type
-
NotSupportedError
Returns:
- Type:
-
Object
The range of the child node, e.g. { start: 0, end: 10 }
Example
const node = espree.parse("function foobar(foo, bar) {}")
childNodeRange(node, "id") // { start: "function ".length, end: "function foobar".length }
// node array
const node = espree.parse("function foobar(foo, bar) {}")
childNodeRange(node, "params") // { start: "function foobar".length, end: "function foobar(foo, bar)".length }
// index for node array
const node = espree.parse("function foobar(foo, bar) {}")
childNodeRange(node, "params.1") // { start: "function foobar(foo, ".length, end: "function foobar(foo, bar".length }
// {name}Property for node who has properties
const node = espree.parse('const foobar = { foo: "foo", bar: "bar" }')
childNodeRange(node, "declarations.0.init.fooProperty") // { start: "const foobar = { ".length, end: "const foobar = { foo".length }
// {name}Value for node who has properties
const node = espree.parse('const foobar = { foo: "foo", bar: "bar" }')
childNodeRange(node, 'declarations.0.init.fooValue')) // { start: "const foobar = { foo: ".length, end: "const foobar = { foo: "foo".length }
// {name}Attribute for node who has attributes
const node = espree.parse('<Field name="email" autoComplete="email" />')
childNodeRange(node, "expression.openingElement.autoCompleteAttribute") // { start: '<Field name="email" '.length, end: '<Field name="email" autoComplete="email"'.length }
// async for MethodDefinition node
const node = espree.parse("async foobar() {}")
childNodeRange(node, "async") // { start: 0, end: "async".length }
// dot for MemberExpression node
const node = espree.parse("foo.bar")
childNodeRange(node, "dot") // { start: "foo".length, end: "foo.".length }
// class for ClassDeclaration node
const node = espree.parse("class FooBar {}")
childNodeRange(node, "class") // { start: 0, end: "class".length }
// semicolon for Property node
const node = espree.parse("{ foo: bar }");
childNodeRange(node, "semicolon") // { start: "{ foo", end: "{ foo:".length }
childNodeValue(node, childName) → {any}
Get the value of child node.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
node |
Node
|
The node to evaluate. |
childName |
string
|
The name to find child node. |
Returns:
- Type:
-
any
The value of child node, it can be a node, an array, a string or a number.
Example
const node = espree.parse("foobar(foo, bar)")
childNodeValue(node, "expression.arguments.0") // node["expression"]["arguments"][0]
// node array
const node = espree.parse("foobar(foo, bar)")
childNodeValue(node, "expression.arguments") // node["expression"]["arguments"]
// {name}Property for node who has properties
const node = espree.parse('const foobar = { foo: "foo", bar: "bar" }')
childNodeValue(node, "declarations.0.init.fooProperty") // node["declarations"][0]["init"]["properties"][0]
// {name}Value for node who has properties
const node = espree.parse('const foobar = { foo: "foo", bar: "bar" }')
childNodeValue(node, 'declarations.0.init.fooValue')) // node["declarations"][0]["init"]["properties"][0]["value"]
// {name}Attribute for node who has attributes
const node = espree.parse('<Field name="email" autoComplete="email" />')
childNodeValue(node, "expression.openingElement.autoCompleteAttribute") // node["expression"]["openingElement"]["attributes"][1]
fileContent() → {string}
Get the source code of current file.
- Source:
Returns:
- Type:
-
string
source code of current file.