Skip to content

Commit 58e1684

Browse files
committed
Merge pull request #94 from eslint/issue93
New: Add sourceType to Program node (fixes #93)
2 parents 9bdaba1 + 3989951 commit 58e1684

File tree

285 files changed

+386
-108
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

285 files changed

+386
-108
lines changed

espree.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -5152,15 +5152,16 @@ function parseSourceElements() {
51525152

51535153
function parseProgram() {
51545154
var body,
5155-
marker;
5155+
marker,
5156+
isModule = !!extra.ecmaFeatures.modules;
51565157

51575158
skipComment();
51585159
peek();
51595160
marker = markerCreate();
5160-
strict = extra.ecmaFeatures.modules;
5161+
strict = isModule;
51615162

51625163
body = parseSourceElements();
5163-
return markerApply(marker, astNodeFactory.createProgram(body));
5164+
return markerApply(marker, astNodeFactory.createProgram(body, isModule ? "module" : "script"));
51645165
}
51655166

51665167
function filterTokenLocation() {

lib/ast-node-factory.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -572,12 +572,14 @@ module.exports = {
572572
/**
573573
* Create an ASTNode representation of an entire program
574574
* @param {ASTNode} body The program body
575+
* @param {string} sourceType Either "module" or "script".
575576
* @returns {ASTNode} An ASTNode representing an entire program
576577
*/
577-
createProgram: function (body) {
578+
createProgram: function (body, sourceType) {
578579
return {
579580
type: astNodeTypes.Program,
580-
body: body
581+
body: body,
582+
sourceType: sourceType
581583
};
582584
},
583585

test/3rdparty/syntax/angular-1.2.5.json

+1-1
Large diffs are not rendered by default.

test/3rdparty/syntax/backbone-1.1.0.json

+1-1
Large diffs are not rendered by default.

test/3rdparty/syntax/jquery-1.9.1.json

+1-1
Large diffs are not rendered by default.

test/3rdparty/syntax/jquery.mobile-1.4.2.json

+1-1
Large diffs are not rendered by default.

test/3rdparty/syntax/mootools-1.4.5.json

+1-1
Large diffs are not rendered by default.

test/3rdparty/syntax/underscore-1.5.2.json

+1-1
Large diffs are not rendered by default.

test/3rdparty/syntax/yui-3.12.0.json

+1-1
Large diffs are not rendered by default.

tests/fixtures/ast/Array-Initializer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
"column": 6
8989
}
9090
},
91+
"sourceType": "script",
9192
"tokens": [
9293
{
9394
"type": "Identifier",
@@ -1194,4 +1195,4 @@
11941195
}
11951196
}
11961197
}
1197-
}
1198+
}

0 commit comments

Comments
 (0)