Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion spec/Machine/cache.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2016-2017 Electric Imp
// Copyright (c) 2016-2020 Electric Imp
// This file is licensed under the MIT License
// http://opensource.org/licenses/MIT

Expand Down Expand Up @@ -159,4 +159,14 @@ describe('FileCache', () => {
});
});

it('should not change includePathParsed object', () => {
let includePath = 'github:electricimp/Builder/spec/fixtures/sample-11/LineBrakeSample.nut';
machine.clearCache();
machine.useCache = true;
const reader = machine._getReader(includePath);
const resFirst = machine.fileCache.read(reader, includePath, machine.dependencies);
const resSecond = machine.fileCache.read(reader, includePath, machine.dependencies);
expect(resSecond.includePathParsed.__PATH__).toBe('github:electricimp/Builder/spec/fixtures/sample-11');
});

});
6 changes: 4 additions & 2 deletions src/FileCache.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// MIT License
//
// Copyright 2016-2019 Electric Imp
// Copyright 2016-2020 Electric Imp
//
// SPDX-License-Identifier: MIT
//
Expand Down Expand Up @@ -139,6 +139,9 @@ class FileCache {
* @private
*/
read(reader, includePath, dependencies) {
// Do this first as our includePath and reader may change on us if we have a cache hit
const includePathParsed = reader.parsePath(includePath);

let needCache = false;
if (!dependencies && this._toBeCached(includePath) && this._isCachedReader(reader)) {
let result;
Expand All @@ -152,7 +155,6 @@ class FileCache {
}
}

const includePathParsed = reader.parsePath(includePath);
let content = reader.read(includePath, { dependencies: dependencies });

// if content doesn't have line separator at the end, then add it
Expand Down
7 changes: 3 additions & 4 deletions src/Machine.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// MIT License
//
// Copyright 2016-2019 Electric Imp
// Copyright 2016-2020 Electric Imp
//
// SPDX-License-Identifier: MIT
//
Expand Down Expand Up @@ -174,7 +174,7 @@ class Machine {
_formatPath(filepath, filename) {
return path.normalize(path.join(filepath, filename));
}

/**
* Execute AST
* @param {[]} ast
Expand Down Expand Up @@ -361,7 +361,7 @@ class Machine {

// if once flag is set, then check if source has already been included
if (once && this._includedSources.has(includePath)) {
this.logger.debug(`Skipping source "${includePath}": has already been included`);
this.logger.debug(`Skipping source "${includePath}" - contents have already been included previously`);
return;
}

Expand Down Expand Up @@ -963,4 +963,3 @@ class Machine {
module.exports = Machine;
module.exports.INSTRUCTIONS = INSTRUCTIONS;
module.exports.Errors = Errors;