Skip to content

Commit 6d4b5d5

Browse files
committed
Handle first-line indentation correctly
1 parent 9222af3 commit 6d4b5d5

File tree

3 files changed

+182
-1
lines changed

3 files changed

+182
-1
lines changed

src/tokenizer/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ export default class Tokenizer {
202202
// whitespace and comments, and.
203203

204204
skipSpace() {
205-
let isNewLine = false; // for lightscript
205+
let isNewLine = this.state.pos === 0; // for lightscript
206206
loop: while (this.state.pos < this.input.length) {
207207
const ch = this.input.charCodeAt(this.state.pos);
208208
switch (ch) {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
if true:
2+
1
3+
else:
4+
2
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
{
2+
"type": "File",
3+
"start": 0,
4+
"end": 30,
5+
"loc": {
6+
"start": {
7+
"line": 1,
8+
"column": 0
9+
},
10+
"end": {
11+
"line": 4,
12+
"column": 5
13+
}
14+
},
15+
"program": {
16+
"type": "Program",
17+
"start": 0,
18+
"end": 30,
19+
"loc": {
20+
"start": {
21+
"line": 1,
22+
"column": 0
23+
},
24+
"end": {
25+
"line": 4,
26+
"column": 5
27+
}
28+
},
29+
"sourceType": "script",
30+
"body": [
31+
{
32+
"type": "IfStatement",
33+
"start": 2,
34+
"end": 30,
35+
"loc": {
36+
"start": {
37+
"line": 1,
38+
"column": 2
39+
},
40+
"end": {
41+
"line": 4,
42+
"column": 5
43+
}
44+
},
45+
"test": {
46+
"type": "BooleanLiteral",
47+
"start": 5,
48+
"end": 9,
49+
"loc": {
50+
"start": {
51+
"line": 1,
52+
"column": 5
53+
},
54+
"end": {
55+
"line": 1,
56+
"column": 9
57+
}
58+
},
59+
"value": true
60+
},
61+
"consequent": {
62+
"type": "BlockStatement",
63+
"start": 9,
64+
"end": 16,
65+
"loc": {
66+
"start": {
67+
"line": 1,
68+
"column": 9
69+
},
70+
"end": {
71+
"line": 2,
72+
"column": 5
73+
}
74+
},
75+
"body": [
76+
{
77+
"type": "ExpressionStatement",
78+
"start": 15,
79+
"end": 16,
80+
"loc": {
81+
"start": {
82+
"line": 2,
83+
"column": 4
84+
},
85+
"end": {
86+
"line": 2,
87+
"column": 5
88+
}
89+
},
90+
"expression": {
91+
"type": "NumericLiteral",
92+
"start": 15,
93+
"end": 16,
94+
"loc": {
95+
"start": {
96+
"line": 2,
97+
"column": 4
98+
},
99+
"end": {
100+
"line": 2,
101+
"column": 5
102+
}
103+
},
104+
"extra": {
105+
"rawValue": 1,
106+
"raw": "1"
107+
},
108+
"value": 1
109+
}
110+
}
111+
],
112+
"directives": [],
113+
"extra": {
114+
"curly": false
115+
}
116+
},
117+
"alternate": {
118+
"type": "BlockStatement",
119+
"start": 23,
120+
"end": 30,
121+
"loc": {
122+
"start": {
123+
"line": 3,
124+
"column": 6
125+
},
126+
"end": {
127+
"line": 4,
128+
"column": 5
129+
}
130+
},
131+
"body": [
132+
{
133+
"type": "ExpressionStatement",
134+
"start": 29,
135+
"end": 30,
136+
"loc": {
137+
"start": {
138+
"line": 4,
139+
"column": 4
140+
},
141+
"end": {
142+
"line": 4,
143+
"column": 5
144+
}
145+
},
146+
"expression": {
147+
"type": "NumericLiteral",
148+
"start": 29,
149+
"end": 30,
150+
"loc": {
151+
"start": {
152+
"line": 4,
153+
"column": 4
154+
},
155+
"end": {
156+
"line": 4,
157+
"column": 5
158+
}
159+
},
160+
"extra": {
161+
"rawValue": 2,
162+
"raw": "2"
163+
},
164+
"value": 2
165+
}
166+
}
167+
],
168+
"directives": [],
169+
"extra": {
170+
"curly": false
171+
}
172+
}
173+
}
174+
],
175+
"directives": []
176+
}
177+
}

0 commit comments

Comments
 (0)