Comparing version 2.0.2 to 2.0.3
@@ -0,1 +1,6 @@ | ||
2.0.3 / 2016-08-24 | ||
================== | ||
* Do not pollute the user's `options` object | ||
2.0.2 / 2016-08-23 | ||
@@ -2,0 +7,0 @@ ================== |
41
index.js
@@ -6,6 +6,7 @@ 'use strict'; | ||
var walk = require('pug-walk'); | ||
var assign = require('object-assign'); | ||
module.exports = load; | ||
function load(ast, options) { | ||
load.validateOptions(options); | ||
options = getOptions(options); | ||
// clone the ast | ||
@@ -22,5 +23,5 @@ ast = JSON.parse(JSON.stringify(ast)); | ||
try { | ||
path = (options.resolve || load.resolve)(file.path, file.filename, options); | ||
path = options.resolve(file.path, file.filename, options); | ||
file.fullPath = path; | ||
str = (options.read || load.read)(path, options); | ||
str = options.read(path, options); | ||
} catch (ex) { | ||
@@ -32,8 +33,5 @@ ex.message += '\n at ' + node.filename + ' line ' + node.line; | ||
if (node.type === 'Extends' || node.type === 'Include') { | ||
var childOptions = {}; | ||
Object.keys(options).forEach(function (key) { | ||
childOptions[key] = options[key]; | ||
}) | ||
childOptions.filename = path; | ||
file.ast = load.string(str, childOptions); | ||
file.ast = load.string(str, assign({}, options, { | ||
filename: path | ||
})); | ||
} | ||
@@ -46,4 +44,5 @@ } | ||
load.string = function loadString(src, options) { | ||
load.validateOptions(options); | ||
options.src = src; | ||
options = assign(getOptions(options), { | ||
src: src | ||
}); | ||
var tokens = options.lex(src, options); | ||
@@ -54,5 +53,6 @@ var ast = options.parse(tokens, options); | ||
load.file = function loadFile(filename, options) { | ||
load.validateOptions(options); | ||
options.filename = filename; | ||
var str = (options.read || load.read)(filename); | ||
options = assign(getOptions(options), { | ||
filename: filename | ||
}); | ||
var str = options.read(filename); | ||
return load.string(str, options); | ||
@@ -78,14 +78,19 @@ } | ||
load.validateOptions = function validateOptions(options) { | ||
/* istanbul ignore if */ | ||
if (typeof options !== 'object') { | ||
throw new TypeError('options must be an object'); | ||
} | ||
/* istanbul ignore if */ | ||
if (typeof options.lex !== 'function') { | ||
throw new TypeError('options.lex must be a function'); | ||
} | ||
/* istanbul ignore if */ | ||
if (typeof options.parse !== 'function') { | ||
throw new TypeError('options.parse must be a function'); | ||
} | ||
/* istanbul ignore if */ | ||
if (options.resolve && typeof options.resolve !== 'function') { | ||
throw new TypeError('options.resolve must be a function'); | ||
} | ||
/* istanbul ignore if */ | ||
if (options.read && typeof options.read !== 'function') { | ||
@@ -95,1 +100,9 @@ throw new TypeError('options.read must be a function'); | ||
}; | ||
function getOptions(options) { | ||
load.validateOptions(options); | ||
return assign({ | ||
resolve: load.resolve, | ||
read: load.read | ||
}, options); | ||
} |
{ | ||
"name": "pug-load", | ||
"version": "2.0.2", | ||
"version": "2.0.3", | ||
"description": "The Pug loader is responsible for loading the depenendencies of a given Pug file.", | ||
@@ -9,2 +9,3 @@ "keywords": [ | ||
"dependencies": { | ||
"object-assign": "^4.1.0", | ||
"pug-walk": "^1.0.0" | ||
@@ -14,6 +15,8 @@ }, | ||
"pug-lexer": "^2.0.0", | ||
"pug-parser": "^2.0.0" | ||
"pug-parser": "^2.0.0", | ||
"istanbul": "*" | ||
}, | ||
"scripts": { | ||
"test": "node test" | ||
"test": "node test", | ||
"coverage": "istanbul cover test" | ||
}, | ||
@@ -20,0 +23,0 @@ "repository": { |
@@ -8,2 +8,3 @@ # pug-load | ||
[![NPM version](https://img.shields.io/npm/v/pug-load.svg)](https://www.npmjs.org/package/pug-load) | ||
[![Coverage Status](https://img.shields.io/codecov/c/github/pugjs/pug-load.svg)](https://codecov.io/gh/pugjs/pug-load) | ||
@@ -10,0 +11,0 @@ ## Installation |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
67579
17
510
105
2
3
1
+ Addedobject-assign@^4.1.0
+ Addedobject-assign@4.1.1(transitive)