Skip to content

Commit 614ec8d

Browse files
committed
Merge pull request #61 from btmills/issue36
Fix: Extend property method range and loc to include params (fixes #36)
2 parents 692b9b1 + b4aa879 commit 614ec8d

File tree

18 files changed

+109
-102
lines changed

18 files changed

+109
-102
lines changed

espree.js

+14-7
Original file line numberDiff line numberDiff line change
@@ -2375,8 +2375,7 @@ function parsePropertyFunction(options) {
23752375
previousYieldAllowed = state.yieldAllowed,
23762376
params = options.params || [],
23772377
defaults = options.defaults || [],
2378-
body,
2379-
marker = markerCreate();
2378+
body;
23802379

23812380
state.yieldAllowed = options.generator;
23822381

@@ -2393,7 +2392,7 @@ function parsePropertyFunction(options) {
23932392
strict = previousStrict;
23942393
state.yieldAllowed = previousYieldAllowed;
23952394

2396-
return markerApply(marker, astNodeFactory.createFunctionExpression(
2395+
return markerApply(options.marker, astNodeFactory.createFunctionExpression(
23972396
null,
23982397
params,
23992398
defaults,
@@ -2406,6 +2405,7 @@ function parsePropertyFunction(options) {
24062405

24072406
function parsePropertyMethodFunction(options) {
24082407
var previousStrict = strict,
2408+
marker = markerCreate(),
24092409
tmp,
24102410
method;
24112411

@@ -2421,7 +2421,8 @@ function parsePropertyMethodFunction(options) {
24212421
params: tmp.params,
24222422
defaults: tmp.defaults,
24232423
rest: tmp.rest,
2424-
generator: options ? options.generator : false
2424+
generator: options ? options.generator : false,
2425+
marker: marker
24252426
});
24262427

24272428
strict = previousStrict;
@@ -2461,7 +2462,7 @@ function parseObjectPropertyKey() {
24612462
}
24622463

24632464
function parseObjectProperty() {
2464-
var token, key, id, param, computed;
2465+
var token, key, id, param, computed, methodMarker;
24652466
var allowComputed = extra.ecmaFeatures.objectLiteralComputedProperties,
24662467
allowMethod = extra.ecmaFeatures.objectLiteralShorthandMethods,
24672468
allowShorthand = extra.ecmaFeatures.objectLiteralShorthandProperties,
@@ -2483,14 +2484,18 @@ function parseObjectProperty() {
24832484
if (token.value === "get" && !(match(":") || match("("))) {
24842485
computed = (lookahead.value === "[");
24852486
key = parseObjectPropertyKey();
2487+
methodMarker = markerCreate();
24862488
expect("(");
24872489
expect(")");
24882490
return markerApply(
24892491
marker,
24902492
astNodeFactory.createProperty(
24912493
"get",
24922494
key,
2493-
parsePropertyFunction({ generator: false }),
2495+
parsePropertyFunction({
2496+
generator: false,
2497+
marker: methodMarker
2498+
}),
24942499
false,
24952500
false,
24962501
computed
@@ -2501,6 +2506,7 @@ function parseObjectProperty() {
25012506
if (token.value === "set" && !(match(":") || match("("))) {
25022507
computed = (lookahead.value === "[");
25032508
key = parseObjectPropertyKey();
2509+
methodMarker = markerCreate();
25042510
expect("(");
25052511
token = lookahead;
25062512
param = [ parseVariableIdentifier() ];
@@ -2513,7 +2519,8 @@ function parseObjectProperty() {
25132519
parsePropertyFunction({
25142520
params: param,
25152521
generator: false,
2516-
name: token
2522+
name: token,
2523+
marker: methodMarker
25172524
}),
25182525
false,
25192526
false,

tests/fixtures/ast/Object-Initializer.json

+34-34
Original file line numberDiff line numberDiff line change
@@ -1219,13 +1219,13 @@
12191219
"generator": false,
12201220
"expression": false,
12211221
"range": [
1222-
18,
1222+
15,
12231223
36
12241224
],
12251225
"loc": {
12261226
"start": {
12271227
"line": 1,
1228-
"column": 18
1228+
"column": 15
12291229
},
12301230
"end": {
12311231
"line": 1,
@@ -1371,13 +1371,13 @@
13711371
"generator": false,
13721372
"expression": false,
13731373
"range": [
1374-
18,
1374+
15,
13751375
20
13761376
],
13771377
"loc": {
13781378
"start": {
13791379
"line": 1,
1380-
"column": 18
1380+
"column": 15
13811381
},
13821382
"end": {
13831383
"line": 1,
@@ -1523,13 +1523,13 @@
15231523
"generator": false,
15241524
"expression": false,
15251525
"range": [
1526-
15,
1526+
12,
15271527
17
15281528
],
15291529
"loc": {
15301530
"start": {
15311531
"line": 1,
1532-
"column": 15
1532+
"column": 12
15331533
},
15341534
"end": {
15351535
"line": 1,
@@ -1675,13 +1675,13 @@
16751675
"generator": false,
16761676
"expression": false,
16771677
"range": [
1678-
17,
1678+
14,
16791679
19
16801680
],
16811681
"loc": {
16821682
"start": {
16831683
"line": 1,
1684-
"column": 17
1684+
"column": 14
16851685
},
16861686
"end": {
16871687
"line": 1,
@@ -1827,13 +1827,13 @@
18271827
"generator": false,
18281828
"expression": false,
18291829
"range": [
1830-
18,
1830+
15,
18311831
20
18321832
],
18331833
"loc": {
18341834
"start": {
18351835
"line": 1,
1836-
"column": 18
1836+
"column": 15
18371837
},
18381838
"end": {
18391839
"line": 1,
@@ -1979,13 +1979,13 @@
19791979
"generator": false,
19801980
"expression": false,
19811981
"range": [
1982-
17,
1982+
14,
19831983
19
19841984
],
19851985
"loc": {
19861986
"start": {
19871987
"line": 1,
1988-
"column": 17
1988+
"column": 14
19891989
},
19901990
"end": {
19911991
"line": 1,
@@ -2132,13 +2132,13 @@
21322132
"generator": false,
21332133
"expression": false,
21342134
"range": [
2135-
20,
2135+
17,
21362136
22
21372137
],
21382138
"loc": {
21392139
"start": {
21402140
"line": 1,
2141-
"column": 20
2141+
"column": 17
21422142
},
21432143
"end": {
21442144
"line": 1,
@@ -2285,13 +2285,13 @@
22852285
"generator": false,
22862286
"expression": false,
22872287
"range": [
2288-
15,
2288+
12,
22892289
17
22902290
],
22912291
"loc": {
22922292
"start": {
22932293
"line": 1,
2294-
"column": 15
2294+
"column": 12
22952295
},
22962296
"end": {
22972297
"line": 1,
@@ -2528,13 +2528,13 @@
25282528
"generator": false,
25292529
"expression": false,
25302530
"range": [
2531-
19,
2531+
15,
25322532
34
25332533
],
25342534
"loc": {
25352535
"start": {
25362536
"line": 1,
2537-
"column": 19
2537+
"column": 15
25382538
},
25392539
"end": {
25402540
"line": 1,
@@ -2771,13 +2771,13 @@
27712771
"generator": false,
27722772
"expression": false,
27732773
"range": [
2774-
16,
2774+
12,
27752775
28
27762776
],
27772777
"loc": {
27782778
"start": {
27792779
"line": 1,
2780-
"column": 16
2780+
"column": 12
27812781
},
27822782
"end": {
27832783
"line": 1,
@@ -3014,13 +3014,13 @@
30143014
"generator": false,
30153015
"expression": false,
30163016
"range": [
3017-
18,
3017+
14,
30183018
32
30193019
],
30203020
"loc": {
30213021
"start": {
30223022
"line": 1,
3023-
"column": 18
3023+
"column": 14
30243024
},
30253025
"end": {
30263026
"line": 1,
@@ -3257,13 +3257,13 @@
32573257
"generator": false,
32583258
"expression": false,
32593259
"range": [
3260-
19,
3260+
15,
32613261
34
32623262
],
32633263
"loc": {
32643264
"start": {
32653265
"line": 1,
3266-
"column": 19
3266+
"column": 15
32673267
},
32683268
"end": {
32693269
"line": 1,
@@ -3500,13 +3500,13 @@
35003500
"generator": false,
35013501
"expression": false,
35023502
"range": [
3503-
18,
3503+
14,
35043504
32
35053505
],
35063506
"loc": {
35073507
"start": {
35083508
"line": 1,
3509-
"column": 18
3509+
"column": 14
35103510
},
35113511
"end": {
35123512
"line": 1,
@@ -3744,13 +3744,13 @@
37443744
"generator": false,
37453745
"expression": false,
37463746
"range": [
3747-
20,
3747+
16,
37483748
34
37493749
],
37503750
"loc": {
37513751
"start": {
37523752
"line": 1,
3753-
"column": 20
3753+
"column": 16
37543754
},
37553755
"end": {
37563756
"line": 1,
@@ -3988,13 +3988,13 @@
39883988
"generator": false,
39893989
"expression": false,
39903990
"range": [
3991-
16,
3991+
12,
39923992
30
39933993
],
39943994
"loc": {
39953995
"start": {
39963996
"line": 1,
3997-
"column": 16
3997+
"column": 12
39983998
},
39993999
"end": {
40004000
"line": 1,
@@ -4697,13 +4697,13 @@
46974697
"generator": false,
46984698
"expression": false,
46994699
"range": [
4700-
18,
4700+
15,
47014701
36
47024702
],
47034703
"loc": {
47044704
"start": {
47054705
"line": 1,
4706-
"column": 18
4706+
"column": 15
47074707
},
47084708
"end": {
47094709
"line": 1,
@@ -4868,13 +4868,13 @@
48684868
"generator": false,
48694869
"expression": false,
48704870
"range": [
4871-
55,
4871+
47,
48724872
75
48734873
],
48744874
"loc": {
48754875
"start": {
48764876
"line": 1,
4877-
"column": 55
4877+
"column": 47
48784878
},
48794879
"end": {
48804880
"line": 1,

0 commit comments

Comments
 (0)