Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: remove sourceCode property from Linter (refs #9161) #9363

Merged
merged 1 commit into from
Sep 29, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 11 additions & 9 deletions lib/linter.js
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,8 @@ const BASE_TRAVERSAL_CONTEXT = Object.freeze(
)
);

const lastSourceCodes = new WeakMap();

//------------------------------------------------------------------------------
// Public Interface
//------------------------------------------------------------------------------
Expand All @@ -708,7 +710,7 @@ const BASE_TRAVERSAL_CONTEXT = Object.freeze(
module.exports = class Linter {

constructor() {
this.sourceCode = null;
lastSourceCodes.set(this, null);
this.version = pkg.version;

this.rules = new Rules();
Expand Down Expand Up @@ -754,11 +756,11 @@ module.exports = class Linter {
const filename = typeof providedFilename === "string" ? providedFilename : "<input>";

if (typeof textOrSourceCode === "string") {
this.sourceCode = null;
lastSourceCodes.set(this, null);
text = textOrSourceCode;
} else {
this.sourceCode = textOrSourceCode;
text = this.sourceCode.text;
lastSourceCodes.set(this, textOrSourceCode);
text = textOrSourceCode.text;
}

// search and apply "eslint-env *".
Expand All @@ -777,13 +779,13 @@ module.exports = class Linter {
// process initial config to make it safe to extend
config = prepareConfig(config, this.environments);

if (this.sourceCode) {
if (lastSourceCodes.get(this)) {
parserServices = {};
} else {

// there's no input, just exit here
if (text.trim().length === 0) {
this.sourceCode = new SourceCode(text, blankScriptAST);
lastSourceCodes.set(this, new SourceCode(text, blankScriptAST));
return [];
}

Expand All @@ -799,11 +801,11 @@ module.exports = class Linter {
}

parserServices = parseResult.services;
this.sourceCode = new SourceCode(text, parseResult.ast);
lastSourceCodes.set(this, new SourceCode(text, parseResult.ast));
}

const problems = [];
const sourceCode = this.sourceCode;
const sourceCode = lastSourceCodes.get(this);
let disableDirectives;

// parse global comments and modify config
Expand Down Expand Up @@ -1005,7 +1007,7 @@ module.exports = class Linter {
* @returns {SourceCode} The SourceCode object.
*/
getSourceCode() {
return this.sourceCode;
return lastSourceCodes.get(this);
}

/**
Expand Down