Skip to content

Commit

Permalink
Chore: remove sourceCode property from Linter (refs #9161) (#9363)
Browse files Browse the repository at this point in the history
  • Loading branch information
not-an-aardvark authored and kaicataldo committed Sep 29, 2017
1 parent cef6f8c commit b1372da
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions lib/linter.js
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

0 comments on commit b1372da

Please sign in to comment.