Skip to content

Commit 3989951

Browse files
committed
New: Add sourceType to Program node (fixes #93)
1 parent 671755e commit 3989951

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
@@ -5158,15 +5158,16 @@ function parseSourceElements() {
51585158

51595159
function parseProgram() {
51605160
var body,
5161-
marker;
5161+
marker,
5162+
isModule = !!extra.ecmaFeatures.modules;
51625163

51635164
skipComment();
51645165
peek();
51655166
marker = markerCreate();
5166-
strict = extra.ecmaFeatures.modules;
5167+
strict = isModule;
51675168

51685169
body = parseSourceElements();
5169-
return markerApply(marker, astNodeFactory.createProgram(body));
5170+
return markerApply(marker, astNodeFactory.createProgram(body, isModule ? "module" : "script"));
51705171
}
51715172

51725173
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)