forked from leechuanjun/TLReactNativeProject
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnode.js
More file actions
executable file
·70 lines (61 loc) · 1.61 KB
/
node.js
File metadata and controls
executable file
·70 lines (61 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import {Parser} from "./state"
import {SourceLocation} from "./location"
// Start an AST node, attaching a start offset.
const pp = Parser.prototype
export class Node {}
pp.startNode = function() {
let node = new Node
node.start = this.start
if (this.options.locations)
node.loc = new SourceLocation(this, this.startLoc)
if (this.options.directSourceFile)
node.sourceFile = this.options.directSourceFile
if (this.options.ranges)
node.range = [this.start, 0]
return node
}
pp.startNodeAt = function(pos, loc) {
let node = new Node
if (Array.isArray(pos)){
if (this.options.locations && loc === undefined) {
// flatten pos
loc = pos[1]
pos = pos[0]
}
}
node.start = pos
if (this.options.locations)
node.loc = new SourceLocation(this, loc)
if (this.options.directSourceFile)
node.sourceFile = this.options.directSourceFile
if (this.options.ranges)
node.range = [pos, 0]
return node
}
// Finish an AST node, adding `type` and `end` properties.
pp.finishNode = function(node, type) {
node.type = type
node.end = this.lastTokEnd
if (this.options.locations)
node.loc.end = this.lastTokEndLoc
if (this.options.ranges)
node.range[1] = this.lastTokEnd
return node
}
// Finish node at given position
pp.finishNodeAt = function(node, type, pos, loc) {
node.type = type
if (Array.isArray(pos)){
if (this.options.locations && loc === undefined) {
// flatten pos
loc = pos[1]
pos = pos[0]
}
}
node.end = pos
if (this.options.locations)
node.loc.end = loc
if (this.options.ranges)
node.range[1] = pos
return node
}