diff --git a/.eslintrc.js b/.eslintrc.js index 186adb77b..f03eac32f 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,14 +1,14 @@ module.exports = { extends: ['eslint:recommended', 'plugin:compat/recommended', 'prettier'], globals: { - self: false + self: false, }, env: { node: true, - es2020: true + es2020: true, }, parserOptions: { - sourceType: 'module' + sourceType: 'module', }, rules: { 'no-console': 'warn', @@ -59,6 +59,6 @@ module.exports = { // ECMAScript 6 // //--------------// - 'no-var': 'error' - } + 'no-var': 'error', + }, }; diff --git a/Gruntfile.js b/Gruntfile.js index d6d022f50..63777dcbe 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,5 +1,5 @@ /* eslint-disable no-process-env */ -module.exports = function(grunt) { +module.exports = function (grunt) { grunt.initConfig({ pkg: grunt.file.readJSON('package.json'), @@ -8,7 +8,7 @@ module.exports = function(grunt) { copy: { dist: { options: { - processContent: function(content) { + processContent: function (content) { return ( grunt.template.process( '/**!\n\n @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt Expat\n <%= pkg.name %> v<%= pkg.version %>\n\n<%= grunt.file.read("LICENSE") %>\n*/\n' @@ -16,9 +16,9 @@ module.exports = function(grunt) { content + '\n// @license-end\n' ); - } + }, }, - files: [{ expand: true, cwd: 'dist/', src: ['*.js'], dest: 'dist/' }] + files: [{ expand: true, cwd: 'dist/', src: ['*.js'], dest: 'dist/' }], }, components: { files: [ @@ -26,18 +26,23 @@ module.exports = function(grunt) { expand: true, cwd: 'components/', src: ['**'], - dest: 'dist/components' + dest: 'dist/components', + }, + { + expand: true, + cwd: 'dist/', + src: ['*.js'], + dest: 'dist/components', }, - { expand: true, cwd: 'dist/', src: ['*.js'], dest: 'dist/components' } - ] - } + ], + }, }, babel: { options: { sourceMaps: 'inline', loose: ['es6.modules'], - auxiliaryCommentBefore: 'istanbul ignore next' + auxiliaryCommentBefore: 'istanbul ignore next', }, cjs: { files: [ @@ -45,10 +50,10 @@ module.exports = function(grunt) { cwd: 'lib/', expand: true, src: '**/!(index).js', - dest: 'dist/cjs/' - } - ] - } + dest: 'dist/cjs/', + }, + ], + }, }, webpack: { options: { @@ -56,28 +61,28 @@ module.exports = function(grunt) { output: { path: 'dist/', library: 'Handlebars', - libraryTarget: 'umd' - } + libraryTarget: 'umd', + }, }, handlebars: { entry: './dist/cjs/handlebars.js', output: { - filename: 'handlebars.js' - } + filename: 'handlebars.js', + }, }, runtime: { entry: './dist/cjs/handlebars.runtime.js', output: { - filename: 'handlebars.runtime.js' - } - } + filename: 'handlebars.runtime.js', + }, + }, }, uglify: { options: { mangle: true, compress: true, - preserveComments: /(?:^!|@(?:license|preserve|cc_on))/ + preserveComments: /(?:^!|@(?:license|preserve|cc_on))/, }, dist: { files: [ @@ -86,19 +91,19 @@ module.exports = function(grunt) { expand: true, src: ['handlebars*.js', '!*.min.js'], dest: 'dist/', - rename: function(dest, src) { + rename: function (dest, src) { return dest + src.replace(/\.js$/, '.min.js'); - } - } - ] - } + }, + }, + ], + }, }, concat: { tests: { src: ['spec/!(require).js'], - dest: 'tmp/tests.js' - } + dest: 'tmp/tests.js', + }, }, connect: { @@ -106,27 +111,27 @@ module.exports = function(grunt) { options: { base: '.', hostname: '*', - port: 9999 - } - } + port: 9999, + }, + }, }, shell: { integrationTests: { - command: './tests/integration/run-integration-tests.sh' - } + command: './tests/integration/run-integration-tests.sh', + }, }, watch: { scripts: { options: { - atBegin: true + atBegin: true, }, files: ['src/*', 'lib/**/*.js', 'spec/**/*.js'], - tasks: ['on-file-change'] - } - } + tasks: ['on-file-change'], + }, + }, }); // Load tasks from npm @@ -148,7 +153,7 @@ module.exports = function(grunt) { 'uglify', 'test:min', 'copy:dist', - 'copy:components' + 'copy:components', ]); // Requires secret properties from .travis.yaml @@ -156,7 +161,7 @@ module.exports = function(grunt) { 'default', 'shell:integrationTests', 'metrics', - 'publish-to-aws' + 'publish-to-aws', ]); grunt.registerTask('on-file-change', ['build', 'concat:tests', 'test']); @@ -174,6 +179,6 @@ module.exports = function(grunt) { ); grunt.registerTask('integration-tests', [ 'default', - 'shell:integrationTests' + 'shell:integrationTests', ]); }; diff --git a/bin/handlebars.js b/bin/handlebars.js index fabbb3951..ee1156c85 100755 --- a/bin/handlebars.js +++ b/bin/handlebars.js @@ -5,103 +5,103 @@ const yargs = require('yargs') .option('f', { type: 'string', description: 'Output File', - alias: 'output' + alias: 'output', }) .option('map', { type: 'string', - description: 'Source Map File' + description: 'Source Map File', }) .option('a', { type: 'boolean', description: 'Exports amd style (require.js)', - alias: 'amd' + alias: 'amd', }) .option('c', { type: 'string', description: 'Exports CommonJS style, path to Handlebars module', alias: 'commonjs', - default: null + default: null, }) .option('h', { type: 'string', description: 'Path to handlebar.js (only valid for amd-style)', alias: 'handlebarPath', - default: '' + default: '', }) .option('k', { type: 'string', description: 'Known helpers', - alias: 'known' + alias: 'known', }) .option('o', { type: 'boolean', description: 'Known helpers only', - alias: 'knownOnly' + alias: 'knownOnly', }) .option('m', { type: 'boolean', description: 'Minimize output', - alias: 'min' + alias: 'min', }) .option('n', { type: 'string', description: 'Template namespace', alias: 'namespace', - default: 'Handlebars.templates' + default: 'Handlebars.templates', }) .option('s', { type: 'boolean', description: 'Output template function only.', - alias: 'simple' + alias: 'simple', }) .option('N', { type: 'string', description: 'Name of passed string templates. Optional if running in a simple mode. Required when operating on multiple templates.', - alias: 'name' + alias: 'name', }) .option('i', { type: 'string', description: 'Generates a template from the passed CLI argument.\n"-" is treated as a special value and causes stdin to be read for the template value.', - alias: 'string' + alias: 'string', }) .option('r', { type: 'string', description: 'Template root. Base value that will be stripped from template names.', - alias: 'root' + alias: 'root', }) .option('p', { type: 'boolean', description: 'Compiling a partial template', - alias: 'partial' + alias: 'partial', }) .option('d', { type: 'boolean', description: 'Include data when compiling', - alias: 'data' + alias: 'data', }) .option('e', { type: 'string', description: 'Template extension.', alias: 'extension', - default: 'handlebars' + default: 'handlebars', }) .option('b', { type: 'boolean', description: 'Removes the BOM (Byte Order Mark) from the beginning of the templates.', - alias: 'bom' + alias: 'bom', }) .option('v', { type: 'boolean', description: 'Prints the current compiler version', - alias: 'version' + alias: 'version', }) .option('help', { type: 'boolean', - description: 'Outputs this message' + description: 'Outputs this message', }) .wrap(120); @@ -110,7 +110,7 @@ argv.files = argv._; delete argv._; const Precompiler = require('../dist/cjs/precompiler'); -Precompiler.loadTemplates(argv, function(err, opts) { +Precompiler.loadTemplates(argv, function (err, opts) { if (err) { throw err; } diff --git a/lib/.eslintrc.js b/lib/.eslintrc.js index 16b3e5907..0bc8d6f5a 100644 --- a/lib/.eslintrc.js +++ b/lib/.eslintrc.js @@ -2,6 +2,6 @@ module.exports = { env: { // Handlebars should run natively in the browser - node: false - } + node: false, + }, }; diff --git a/lib/handlebars.js b/lib/handlebars.js index 64a288c35..68a505a20 100644 --- a/lib/handlebars.js +++ b/lib/handlebars.js @@ -2,7 +2,7 @@ import { parser as Parser, parse, parseWithoutProcessing, - Visitor + Visitor, } from '@handlebars/parser'; import runtime from './handlebars.runtime'; @@ -18,10 +18,10 @@ let _create = runtime.create; function create() { let hb = _create(); - hb.compile = function(input, options) { + hb.compile = function (input, options) { return compile(input, options, hb); }; - hb.precompile = function(input, options) { + hb.precompile = function (input, options) { return precompile(input, options, hb); }; diff --git a/lib/handlebars.runtime.js b/lib/handlebars.runtime.js index 6b6270b2f..9d33940f2 100644 --- a/lib/handlebars.runtime.js +++ b/lib/handlebars.runtime.js @@ -20,7 +20,7 @@ function create() { hb.escapeExpression = Utils.escapeExpression; hb.VM = runtime; - hb.template = function(spec) { + hb.template = function (spec) { return runtime.template(spec, hb); }; diff --git a/lib/handlebars/base.js b/lib/handlebars/base.js index a84243f5d..371398f4a 100644 --- a/lib/handlebars/base.js +++ b/lib/handlebars/base.js @@ -17,7 +17,7 @@ export const REVISION_CHANGES = { 5: '== 2.0.0-alpha.x', 6: '>= 2.0.0-beta.1', 7: '>= 4.0.0 <4.3.0', - 8: '>= 4.3.0' + 8: '>= 4.3.0', }; const objectType = '[object Object]'; @@ -37,7 +37,7 @@ HandlebarsEnvironment.prototype = { logger: logger, log: logger.log, - registerHelper: function(name, fn) { + registerHelper: function (name, fn) { if (toString.call(name) === objectType) { if (fn) { throw new Exception('Arg not supported with multiple helpers'); @@ -47,11 +47,11 @@ HandlebarsEnvironment.prototype = { this.helpers[name] = fn; } }, - unregisterHelper: function(name) { + unregisterHelper: function (name) { delete this.helpers[name]; }, - registerPartial: function(name, partial) { + registerPartial: function (name, partial) { if (toString.call(name) === objectType) { extend(this.partials, name); } else { @@ -63,11 +63,11 @@ HandlebarsEnvironment.prototype = { this.partials[name] = partial; } }, - unregisterPartial: function(name) { + unregisterPartial: function (name) { delete this.partials[name]; }, - registerDecorator: function(name, fn) { + registerDecorator: function (name, fn) { if (toString.call(name) === objectType) { if (fn) { throw new Exception('Arg not supported with multiple decorators'); @@ -77,7 +77,7 @@ HandlebarsEnvironment.prototype = { this.decorators[name] = fn; } }, - unregisterDecorator: function(name) { + unregisterDecorator: function (name) { delete this.decorators[name]; }, /** @@ -86,7 +86,7 @@ HandlebarsEnvironment.prototype = { */ resetLoggedPropertyAccesses() { resetLoggedProperties(); - } + }, }; export let log = logger.log; diff --git a/lib/handlebars/compiler/ast.js b/lib/handlebars/compiler/ast.js index d77629a52..ee1cb5727 100644 --- a/lib/handlebars/compiler/ast.js +++ b/lib/handlebars/compiler/ast.js @@ -4,7 +4,7 @@ let AST = { // a mustache is definitely a helper if: // * it is an eligible helper, and // * it has at least one parameter or hash segment - helperExpression: function(node) { + helperExpression: function (node) { return ( node.type === 'SubExpression' || ((node.type === 'MustacheStatement' || @@ -13,18 +13,18 @@ let AST = { ); }, - scopedId: function(path) { + scopedId: function (path) { return /^\.|this\b/.test(path.original); }, // an ID is simple if it only has one part, and that part is not // `..` or `this`. - simpleId: function(path) { + simpleId: function (path) { return ( path.parts.length === 1 && !AST.helpers.scopedId(path) && !path.depth ); - } - } + }, + }, }; // Must be exported as an object rather than the root of the module as the jison lexer diff --git a/lib/handlebars/compiler/code-gen.js b/lib/handlebars/compiler/code-gen.js index 9feb61096..2d03e9798 100644 --- a/lib/handlebars/compiler/code-gen.js +++ b/lib/handlebars/compiler/code-gen.js @@ -17,7 +17,7 @@ try { /* istanbul ignore if: tested but not covered in istanbul due to dist build */ if (!SourceNode) { - SourceNode = function(line, column, srcFile, chunks) { + SourceNode = function (line, column, srcFile, chunks) { this.src = ''; if (chunks) { this.add(chunks); @@ -25,24 +25,24 @@ if (!SourceNode) { }; /* istanbul ignore next */ SourceNode.prototype = { - add: function(chunks) { + add: function (chunks) { if (isArray(chunks)) { chunks = chunks.join(''); } this.src += chunks; }, - prepend: function(chunks) { + prepend: function (chunks) { if (isArray(chunks)) { chunks = chunks.join(''); } this.src = chunks + this.src; }, - toStringWithSourceMap: function() { + toStringWithSourceMap: function () { return { code: this.toString() }; }, - toString: function() { + toString: function () { return this.src; - } + }, }; } @@ -70,32 +70,32 @@ CodeGen.prototype = { isEmpty() { return !this.source.length; }, - prepend: function(source, loc) { + prepend: function (source, loc) { this.source.unshift(this.wrap(source, loc)); }, - push: function(source, loc) { + push: function (source, loc) { this.source.push(this.wrap(source, loc)); }, - merge: function() { + merge: function () { let source = this.empty(); - this.each(function(line) { + this.each(function (line) { source.add([' ', line, '\n']); }); return source; }, - each: function(iter) { + each: function (iter) { for (let i = 0, len = this.source.length; i < len; i++) { iter(this.source[i]); } }, - empty: function() { + empty: function () { let loc = this.currentLocation || { start: {} }; return new SourceNode(loc.start.line, loc.start.column, this.srcFile); }, - wrap: function(chunk, loc = this.currentLocation || { start: {} }) { + wrap: function (chunk, loc = this.currentLocation || { start: {} }) { if (chunk instanceof SourceNode) { return chunk; } @@ -110,12 +110,12 @@ CodeGen.prototype = { ); }, - functionCall: function(fn, type, params) { + functionCall: function (fn, type, params) { params = this.generateList(params); return this.wrap([fn, type ? '.' + type + '(' : '(', params, ')']); }, - quotedString: function(str) { + quotedString: function (str) { return ( '"' + (str + '') @@ -129,10 +129,10 @@ CodeGen.prototype = { ); }, - objectLiteral: function(obj) { + objectLiteral: function (obj) { let pairs = []; - Object.keys(obj).forEach(key => { + Object.keys(obj).forEach((key) => { let value = castChunk(obj[key], this); if (value !== 'undefined') { pairs.push([this.quotedString(key), ':', value]); @@ -145,7 +145,7 @@ CodeGen.prototype = { return ret; }, - generateList: function(entries) { + generateList: function (entries) { let ret = this.empty(); for (let i = 0, len = entries.length; i < len; i++) { @@ -159,13 +159,13 @@ CodeGen.prototype = { return ret; }, - generateArray: function(entries) { + generateArray: function (entries) { let ret = this.generateList(entries); ret.prepend('['); ret.add(']'); return ret; - } + }, }; export default CodeGen; diff --git a/lib/handlebars/compiler/compiler.js b/lib/handlebars/compiler/compiler.js index 83a13ab51..d68a0062d 100644 --- a/lib/handlebars/compiler/compiler.js +++ b/lib/handlebars/compiler/compiler.js @@ -16,7 +16,7 @@ export function Compiler() {} Compiler.prototype = { compiler: Compiler, - equals: function(other) { + equals: function (other) { let len = this.opcodes.length; if (other.opcodes.length !== len) { return false; @@ -47,7 +47,7 @@ Compiler.prototype = { guid: 0, - compile: function(program, options) { + compile: function (program, options) { this.sourceNode = []; this.opcodes = []; this.children = []; @@ -65,7 +65,7 @@ Compiler.prototype = { unless: true, with: true, log: true, - lookup: true + lookup: true, }, options.knownHelpers ); @@ -73,7 +73,7 @@ Compiler.prototype = { return this.accept(program); }, - compileProgram: function(program) { + compileProgram: function (program) { let childCompiler = new this.compiler(), // eslint-disable-line new-cap result = childCompiler.compile(program, this.options), guid = this.guid++; @@ -86,7 +86,7 @@ Compiler.prototype = { return guid; }, - accept: function(node) { + accept: function (node) { /* istanbul ignore next: Sanity code */ if (!this[node.type]) { throw new Exception('Unknown type: ' + node.type, node); @@ -98,7 +98,7 @@ Compiler.prototype = { return ret; }, - Program: function(program) { + Program: function (program) { this.options.blockParams.unshift(program.blockParams); let body = program.body, @@ -115,7 +115,7 @@ Compiler.prototype = { return this; }, - BlockStatement: function(block) { + BlockStatement: function (block) { transformLiteralToPath(block); let program = block.program, @@ -160,7 +160,7 @@ Compiler.prototype = { this.opcode('registerDecorator', params.length, path.original); }, - PartialStatement: function(partial) { + PartialStatement: function (partial) { this.usePartial = true; let program = partial.program; @@ -199,11 +199,11 @@ Compiler.prototype = { this.opcode('invokePartial', isDynamic, partialName, indent); this.opcode('append'); }, - PartialBlockStatement: function(partialBlock) { + PartialBlockStatement: function (partialBlock) { this.PartialStatement(partialBlock); }, - MustacheStatement: function(mustache) { + MustacheStatement: function (mustache) { this.SubExpression(mustache); if (mustache.escaped && !this.options.noEscape) { @@ -216,15 +216,15 @@ Compiler.prototype = { this.DecoratorBlock(decorator); }, - ContentStatement: function(content) { + ContentStatement: function (content) { if (content.value) { this.opcode('appendContent', content.value); } }, - CommentStatement: function() {}, + CommentStatement: function () {}, - SubExpression: function(sexpr) { + SubExpression: function (sexpr) { transformLiteralToPath(sexpr); let type = this.classifySexpr(sexpr); @@ -236,7 +236,7 @@ Compiler.prototype = { this.ambiguousSexpr(sexpr); } }, - ambiguousSexpr: function(sexpr, program, inverse) { + ambiguousSexpr: function (sexpr, program, inverse) { let path = sexpr.path, name = path.parts[0], isBlock = program != null || inverse != null; @@ -252,14 +252,14 @@ Compiler.prototype = { this.opcode('invokeAmbiguous', name, isBlock); }, - simpleSexpr: function(sexpr) { + simpleSexpr: function (sexpr) { let path = sexpr.path; path.strict = true; this.accept(path); this.opcode('resolvePossibleLambda'); }, - helperSexpr: function(sexpr, program, inverse) { + helperSexpr: function (sexpr, program, inverse) { let params = this.setupFullMustacheParams(sexpr, program, inverse), path = sexpr.path, name = path.parts[0]; @@ -285,7 +285,7 @@ Compiler.prototype = { } }, - PathExpression: function(path) { + PathExpression: function (path) { this.addDepth(path.depth); this.opcode('getContext', path.depth); @@ -312,27 +312,27 @@ Compiler.prototype = { } }, - StringLiteral: function(string) { + StringLiteral: function (string) { this.opcode('pushString', string.value); }, - NumberLiteral: function(number) { + NumberLiteral: function (number) { this.opcode('pushLiteral', number.value); }, - BooleanLiteral: function(bool) { + BooleanLiteral: function (bool) { this.opcode('pushLiteral', bool.value); }, - UndefinedLiteral: function() { + UndefinedLiteral: function () { this.opcode('pushLiteral', 'undefined'); }, - NullLiteral: function() { + NullLiteral: function () { this.opcode('pushLiteral', 'null'); }, - Hash: function(hash) { + Hash: function (hash) { let pairs = hash.pairs, i = 0, l = pairs.length; @@ -349,15 +349,15 @@ Compiler.prototype = { }, // HELPERS - opcode: function(name) { + opcode: function (name) { this.opcodes.push({ opcode: name, args: slice.call(arguments, 1), - loc: this.sourceNode[0].loc + loc: this.sourceNode[0].loc, }); }, - addDepth: function(depth) { + addDepth: function (depth) { if (!depth) { return; } @@ -365,7 +365,7 @@ Compiler.prototype = { this.useDepths = true; }, - classifySexpr: function(sexpr) { + classifySexpr: function (sexpr) { let isSimple = AST.helpers.simpleId(sexpr.path); let isBlockParam = isSimple && !!this.blockParamIndex(sexpr.path.parts[0]); @@ -400,17 +400,17 @@ Compiler.prototype = { } }, - pushParams: function(params) { + pushParams: function (params) { for (let i = 0, l = params.length; i < l; i++) { this.pushParam(params[i]); } }, - pushParam: function(val) { + pushParam: function (val) { this.accept(val); }, - setupFullMustacheParams: function(sexpr, program, inverse, omitEmpty) { + setupFullMustacheParams: function (sexpr, program, inverse, omitEmpty) { let params = sexpr.params; this.pushParams(params); @@ -426,7 +426,7 @@ Compiler.prototype = { return params; }, - blockParamIndex: function(name) { + blockParamIndex: function (name) { for ( let depth = 0, len = this.options.blockParams.length; depth < len; @@ -438,7 +438,7 @@ Compiler.prototype = { return [depth, param]; } } - } + }, }; export function precompile(input, options = {}, env) { @@ -467,7 +467,7 @@ export function compile(input, options = {}, env) { } // Template is only compiled on first use and cached after that point. - return function(context, execOptions) { + return function (context, execOptions) { if (!compiled) { compiled = compileInput(); } @@ -530,7 +530,7 @@ function transformLiteralToPath(sexpr) { depth: 0, parts: [literal.original + ''], original: literal.original + '', - loc: literal.loc + loc: literal.loc, }; } } diff --git a/lib/handlebars/compiler/javascript-compiler.js b/lib/handlebars/compiler/javascript-compiler.js index d33975e30..678b42b02 100644 --- a/lib/handlebars/compiler/javascript-compiler.js +++ b/lib/handlebars/compiler/javascript-compiler.js @@ -12,25 +12,25 @@ function JavaScriptCompiler() {} JavaScriptCompiler.prototype = { // PUBLIC API: You can override these methods in a subclass to provide // alternative compiled forms for name lookup and buffering semantics - nameLookup: function(parent, name /*, type */) { + nameLookup: function (parent, name /*, type */) { return this.internalNameLookup(parent, name); }, - depthedLookup: function(name) { + depthedLookup: function (name) { return [ this.aliasable('container.lookup'), '(depths, ', JSON.stringify(name), - ')' + ')', ]; }, - compilerInfo: function() { + compilerInfo: function () { const revision = COMPILER_REVISION, versions = REVISION_CHANGES[revision]; return [revision, versions]; }, - appendToBuffer: function(source, location, explicit) { + appendToBuffer: function (source, location, explicit) { // Force a source as this simplifies the merge logic. if (!isArray(source)) { source = [source]; @@ -50,18 +50,18 @@ JavaScriptCompiler.prototype = { } }, - initializeBuffer: function() { + initializeBuffer: function () { return this.quotedString(''); }, // END PUBLIC API - internalNameLookup: function(parent, name) { + internalNameLookup: function (parent, name) { this.lookupPropertyFunctionIsUsed = true; return ['lookupProperty(', parent, ',', JSON.stringify(name), ')']; }, lookupPropertyFunctionIsUsed: false, - compile: function(environment, options, context, asObject) { + compile: function (environment, options, context, asObject) { this.environment = environment; this.options = options; this.precompile = !asObject; @@ -71,7 +71,7 @@ JavaScriptCompiler.prototype = { this.context = context || { decorators: [], programs: [], - environments: [] + environments: [], }; this.preamble(); @@ -123,7 +123,7 @@ JavaScriptCompiler.prototype = { this.decorators.prepend([ 'var decorators = container.decorators, ', this.lookupPropertyFunctionVarDeclaration(), - ';\n' + ';\n', ]); this.decorators.push('return fn;'); @@ -137,7 +137,7 @@ JavaScriptCompiler.prototype = { 'data', 'blockParams', 'depths', - this.decorators.merge() + this.decorators.merge(), ]); } else { this.decorators.prepend( @@ -154,7 +154,7 @@ JavaScriptCompiler.prototype = { if (!this.isChild) { let ret = { compiler: this.compilerInfo(), - main: fn + main: fn, }; if (this.decorators) { @@ -211,7 +211,7 @@ JavaScriptCompiler.prototype = { } }, - preamble: function() { + preamble: function () { // track the last context pushed into place to allow skipping the // getContext opcode when it would be a noop this.lastContext = 0; @@ -219,7 +219,7 @@ JavaScriptCompiler.prototype = { this.decorators = new CodeGen(this.options.srcName); }, - createFunctionContext: function(asObject) { + createFunctionContext: function (asObject) { let varDeclarations = ''; let locals = this.stackVars.concat(this.registers.list); @@ -234,7 +234,7 @@ JavaScriptCompiler.prototype = { // aliases will not be used, but this case is already being run on the client and // we aren't concern about minimizing the template size. let aliasCount = 0; - Object.keys(this.aliases).forEach(alias => { + Object.keys(this.aliases).forEach((alias) => { let node = this.aliases[alias]; if (node.children && node.referenceCount > 1) { varDeclarations += ', alias' + ++aliasCount + '=' + alias; @@ -268,18 +268,18 @@ JavaScriptCompiler.prototype = { params.join(','), ') {\n ', source, - '}' + '}', ]); } }, - mergeSource: function(varDeclarations) { + mergeSource: function (varDeclarations) { let isSimple = this.environment.isSimple, appendOnly = !this.forceBuffer, appendFirst, sourceSeen, bufferStart, bufferEnd; - this.source.each(line => { + this.source.each((line) => { if (line.appendToBuffer) { if (bufferStart) { line.prepend(' + '); @@ -333,7 +333,7 @@ JavaScriptCompiler.prototype = { return this.source.merge(); }, - lookupPropertyFunctionVarDeclaration: function() { + lookupPropertyFunctionVarDeclaration: function () { return ` lookupProperty = container.lookupProperty || function(parent, propertyName) { if (Object.prototype.hasOwnProperty.call(parent, propertyName)) { @@ -353,7 +353,7 @@ JavaScriptCompiler.prototype = { // `{{#this.foo}}...{{/this.foo}}`, resolve the value of `foo`, and // replace it on the stack with the result of properly // invoking blockHelperMissing. - blockValue: function(name) { + blockValue: function (name) { let blockHelperMissing = this.aliasable( 'container.hooks.blockHelperMissing' ), @@ -372,7 +372,7 @@ JavaScriptCompiler.prototype = { // Compiler value, before: lastHelper=value of last found helper, if any // On stack, after, if no lastHelper: same as [blockValue] // On stack, after, if lastHelper: value - ambiguousBlockValue: function() { + ambiguousBlockValue: function () { // We're being a bit cheeky and reusing the options value from the prior exec let blockHelperMissing = this.aliasable( 'container.hooks.blockHelperMissing' @@ -392,7 +392,7 @@ JavaScriptCompiler.prototype = { current, ' = ', this.source.functionCall(blockHelperMissing, 'call', params), - '}' + '}', ]); }, @@ -402,7 +402,7 @@ JavaScriptCompiler.prototype = { // On stack, after: ... // // Appends the string value of `content` to the current buffer - appendContent: function(content) { + appendContent: function (content) { if (this.pendingContent) { content = this.pendingContent + content; } else { @@ -421,9 +421,9 @@ JavaScriptCompiler.prototype = { // // If `value` is truthy, or 0, it is coerced into a string and appended // Otherwise, the empty string is appended - append: function() { + append: function () { if (this.isInline()) { - this.replaceStack(current => [' != null ? ', current, ' : ""']); + this.replaceStack((current) => [' != null ? ', current, ' : ""']); this.pushSource(this.appendToBuffer(this.popStack())); } else { @@ -433,13 +433,13 @@ JavaScriptCompiler.prototype = { local, ' != null) { ', this.appendToBuffer(local, undefined, true), - ' }' + ' }', ]); if (this.environment.isSimple) { this.pushSource([ 'else { ', this.appendToBuffer("''", undefined, true), - ' }' + ' }', ]); } } @@ -451,13 +451,13 @@ JavaScriptCompiler.prototype = { // On stack, after: ... // // Escape `value` and append it to the buffer - appendEscaped: function() { + appendEscaped: function () { this.pushSource( this.appendToBuffer([ this.aliasable('container.escapeExpression'), '(', this.popStack(), - ')' + ')', ]) ); }, @@ -469,7 +469,7 @@ JavaScriptCompiler.prototype = { // Compiler value, after: lastContext=depth // // Set the value of the `lastContext` compiler value to the depth - getContext: function(depth) { + getContext: function (depth) { this.lastContext = depth; }, @@ -479,7 +479,7 @@ JavaScriptCompiler.prototype = { // On stack, after: currentContext, ... // // Pushes the value of the current context onto the stack. - pushContext: function() { + pushContext: function () { this.pushStackLiteral(this.contextName(this.lastContext)); }, @@ -490,7 +490,7 @@ JavaScriptCompiler.prototype = { // // Looks up the value of `name` on the current context and pushes // it onto the stack. - lookupOnContext: function(parts, falsy, strict, scoped) { + lookupOnContext: function (parts, falsy, strict, scoped) { let i = 0; if (!scoped && this.options.compat && !this.lastContext) { @@ -511,7 +511,7 @@ JavaScriptCompiler.prototype = { // // Looks up the value of `parts` on the given block param and pushes // it onto the stack. - lookupBlockParam: function(blockParamId, parts) { + lookupBlockParam: function (blockParamId, parts) { this.useBlockParams = true; this.push(['blockParams[', blockParamId[0], '][', blockParamId[1], ']']); @@ -524,7 +524,7 @@ JavaScriptCompiler.prototype = { // On stack, after: data, ... // // Push the data lookup operator - lookupData: function(depth, parts, strict) { + lookupData: function (depth, parts, strict) { if (!depth) { this.pushStackLiteral('data'); } else { @@ -534,7 +534,7 @@ JavaScriptCompiler.prototype = { this.resolvePath('data', parts, 0, true, strict); }, - resolvePath: function(type, parts, i, falsy, strict) { + resolvePath: function (type, parts, i, falsy, strict) { if (this.options.strict || this.options.assumeObjects) { this.push( strictLookup(this.options.strict && strict, this, parts, i, type) @@ -545,7 +545,7 @@ JavaScriptCompiler.prototype = { let len = parts.length; for (; i < len; i++) { /* eslint-disable no-loop-func */ - this.replaceStack(current => { + this.replaceStack((current) => { let lookup = this.nameLookup(current, parts[i], type); // We want to ensure that zero and false are handled properly if the context (falsy flag) // needs to have the special handling for these values. @@ -567,27 +567,27 @@ JavaScriptCompiler.prototype = { // // If the `value` is a lambda, replace it on the stack by // the return value of the lambda - resolvePossibleLambda: function() { + resolvePossibleLambda: function () { this.push([ this.aliasable('container.lambda'), '(', this.popStack(), ', ', this.contextName(0), - ')' + ')', ]); }, - emptyHash: function(omitEmpty) { + emptyHash: function (omitEmpty) { this.pushStackLiteral(omitEmpty ? 'undefined' : '{}'); }, - pushHash: function() { + pushHash: function () { if (this.hash) { this.hashes.push(this.hash); } this.hash = { values: {} }; }, - popHash: function() { + popHash: function () { let hash = this.hash; this.hash = this.hashes.pop(); @@ -600,7 +600,7 @@ JavaScriptCompiler.prototype = { // On stack, after: quotedString(string), ... // // Push a quoted version of `string` onto the stack - pushString: function(string) { + pushString: function (string) { this.pushStackLiteral(this.quotedString(string)); }, @@ -612,7 +612,7 @@ JavaScriptCompiler.prototype = { // Pushes a value onto the stack. This operation prevents // the compiler from creating a temporary variable to hold // it. - pushLiteral: function(value) { + pushLiteral: function (value) { this.pushStackLiteral(value); }, @@ -624,7 +624,7 @@ JavaScriptCompiler.prototype = { // Push a program expression onto the stack. This takes // a compile-time guid and converts it into a runtime-accessible // expression. - pushProgram: function(guid) { + pushProgram: function (guid) { if (guid != null) { this.pushStackLiteral(this.programExpression(guid)); } else { @@ -649,9 +649,9 @@ JavaScriptCompiler.prototype = { 'fn', 'props', 'container', - options + options, ]), - ' || fn;' + ' || fn;', ]); }, @@ -664,7 +664,7 @@ JavaScriptCompiler.prototype = { // and pushes the helper's return value onto the stack. // // If the helper is not found, `helperMissing` is called. - invokeHelper: function(paramSize, name, isSimple) { + invokeHelper: function (paramSize, name, isSimple) { let nonHelper = this.popStack(), helper = this.setupHelper(paramSize, name); @@ -685,7 +685,7 @@ JavaScriptCompiler.prototype = { let functionLookupCode = [ '(', this.itemsSeparatedBy(possibleFunctionCalls, '||'), - ')' + ')', ]; let functionCall = this.source.functionCall( functionLookupCode, @@ -695,7 +695,7 @@ JavaScriptCompiler.prototype = { this.push(functionCall); }, - itemsSeparatedBy: function(items, separator) { + itemsSeparatedBy: function (items, separator) { let result = []; result.push(items[0]); for (let i = 1; i < items.length; i++) { @@ -710,7 +710,7 @@ JavaScriptCompiler.prototype = { // // This operation is used when the helper is known to exist, // so a `helperMissing` fallback is not required. - invokeKnownHelper: function(paramSize, name) { + invokeKnownHelper: function (paramSize, name) { let helper = this.setupHelper(paramSize, name); this.push(this.source.functionCall(helper.name, 'call', helper.callParams)); }, @@ -727,7 +727,7 @@ JavaScriptCompiler.prototype = { // This operation emits more code than the other options, // and can be avoided by passing the `knownHelpers` and // `knownHelpersOnly` flags at compile-time. - invokeAmbiguous: function(name, helperCall) { + invokeAmbiguous: function (name, helperCall) { this.useRegister('helper'); let nonHelper = this.popStack(); @@ -759,7 +759,7 @@ JavaScriptCompiler.prototype = { this.aliasable('"function"'), ' ? ', this.source.functionCall('helper', 'call', helper.callParams), - ' : helper))' + ' : helper))', ]); }, @@ -770,7 +770,7 @@ JavaScriptCompiler.prototype = { // // This operation pops off a context, invokes a partial with that context, // and pushes the result of the invocation back. - invokePartial: function(isDynamic, name, indent) { + invokePartial: function (isDynamic, name, indent) { let params = [], options = this.setupParams(name, 1, params); @@ -807,7 +807,7 @@ JavaScriptCompiler.prototype = { // On stack, after: ..., hash, ... // // Pops a value off the stack and assigns it to the current hash - assignToHash: function(key) { + assignToHash: function (key) { this.hash.values[key] = this.popStack(); }, @@ -815,7 +815,7 @@ JavaScriptCompiler.prototype = { compiler: JavaScriptCompiler, - compileChildren: function(environment, options) { + compileChildren: function (environment, options) { let children = environment.children, child, compiler; @@ -853,7 +853,7 @@ JavaScriptCompiler.prototype = { } } }, - matchExistingProgram: function(child) { + matchExistingProgram: function (child) { for (let i = 0, len = this.context.environments.length; i < len; i++) { let environment = this.context.environments[i]; if (environment && environment.equals(child)) { @@ -862,7 +862,7 @@ JavaScriptCompiler.prototype = { } }, - programExpression: function(guid) { + programExpression: function (guid) { let child = this.environment.children[guid], programParams = [child.index, 'data', child.blockParams]; @@ -876,14 +876,14 @@ JavaScriptCompiler.prototype = { return 'container.program(' + programParams.join(', ') + ')'; }, - useRegister: function(name) { + useRegister: function (name) { if (!this.registers[name]) { this.registers[name] = true; this.registers.list.push(name); } }, - push: function(expr) { + push: function (expr) { if (!(expr instanceof Literal)) { expr = this.source.wrap(expr); } @@ -892,11 +892,11 @@ JavaScriptCompiler.prototype = { return expr; }, - pushStackLiteral: function(item) { + pushStackLiteral: function (item) { this.push(new Literal(item)); }, - pushSource: function(source) { + pushSource: function (source) { if (this.pendingContent) { this.source.push( this.appendToBuffer( @@ -912,7 +912,7 @@ JavaScriptCompiler.prototype = { } }, - replaceStack: function(callback) { + replaceStack: function (callback) { let prefix = ['('], stack, createdStack, @@ -951,17 +951,17 @@ JavaScriptCompiler.prototype = { this.push(prefix.concat(item, ')')); }, - incrStack: function() { + incrStack: function () { this.stackSlot++; if (this.stackSlot > this.stackVars.length) { this.stackVars.push('stack' + this.stackSlot); } return this.topStackName(); }, - topStackName: function() { + topStackName: function () { return 'stack' + this.stackSlot; }, - flushInline: function() { + flushInline: function () { let inlineStack = this.inlineStack; this.inlineStack = []; for (let i = 0, len = inlineStack.length; i < len; i++) { @@ -976,11 +976,11 @@ JavaScriptCompiler.prototype = { } } }, - isInline: function() { + isInline: function () { return this.inlineStack.length; }, - popStack: function(wrapped) { + popStack: function (wrapped) { let inline = this.isInline(), item = (inline ? this.inlineStack : this.compileStack).pop(); @@ -998,7 +998,7 @@ JavaScriptCompiler.prototype = { } }, - topStack: function() { + topStack: function () { let stack = this.isInline() ? this.inlineStack : this.compileStack, item = stack[stack.length - 1]; @@ -1010,7 +1010,7 @@ JavaScriptCompiler.prototype = { } }, - contextName: function(context) { + contextName: function (context) { if (this.useDepths && context) { return 'depths[' + context + ']'; } else { @@ -1018,15 +1018,15 @@ JavaScriptCompiler.prototype = { } }, - quotedString: function(str) { + quotedString: function (str) { return this.source.quotedString(str); }, - objectLiteral: function(obj) { + objectLiteral: function (obj) { return this.source.objectLiteral(obj); }, - aliasable: function(name) { + aliasable: function (name) { let ret = this.aliases[name]; if (ret) { ret.referenceCount++; @@ -1040,7 +1040,7 @@ JavaScriptCompiler.prototype = { return ret; }, - setupHelper: function(paramSize, name, blockHelper) { + setupHelper: function (paramSize, name, blockHelper) { let params = [], paramsInit = this.setupHelperArgs(name, paramSize, params, blockHelper); let foundHelper = this.nameLookup('helpers', name, 'helper'), @@ -1054,11 +1054,11 @@ JavaScriptCompiler.prototype = { params: params, paramsInit: paramsInit, name: foundHelper, - callParams: [callContext].concat(params) + callParams: [callContext].concat(params), }; }, - setupParams: function(helper, paramSize, params) { + setupParams: function (helper, paramSize, params) { let options = {}, objectArgs = !params, param; @@ -1101,7 +1101,7 @@ JavaScriptCompiler.prototype = { return options; }, - setupHelperArgs: function(helper, paramSize, params, useRegister) { + setupHelperArgs: function (helper, paramSize, params, useRegister) { let options = this.setupParams(helper, paramSize, params); options.loc = JSON.stringify(this.source.currentLocation); options = this.objectLiteral(options); @@ -1115,10 +1115,10 @@ JavaScriptCompiler.prototype = { } else { return options; } - } + }, }; -(function() { +(function () { const reservedWords = ( 'break else new var' + ' case finally return void' + @@ -1148,7 +1148,7 @@ JavaScriptCompiler.prototype = { /** * @deprecated May be removed in the next major version */ -JavaScriptCompiler.isValidJavaScriptVariableName = function(name) { +JavaScriptCompiler.isValidJavaScriptVariableName = function (name) { return ( !JavaScriptCompiler.RESERVED_WORDS[name] && /^[a-zA-Z_$][0-9a-zA-Z_$]*$/.test(name) @@ -1175,7 +1175,7 @@ function strictLookup(requireTerminal, compiler, parts, i, type) { compiler.quotedString(parts[i]), ', ', JSON.stringify(compiler.source.currentLocation), - ' )' + ' )', ]; } else { return stack; diff --git a/lib/handlebars/decorators/inline.js b/lib/handlebars/decorators/inline.js index 02f5be7b5..fe7a437a0 100644 --- a/lib/handlebars/decorators/inline.js +++ b/lib/handlebars/decorators/inline.js @@ -1,22 +1,25 @@ import { extend } from '../utils'; -export default function(instance) { - instance.registerDecorator('inline', function(fn, props, container, options) { - let ret = fn; - if (!props.partials) { - props.partials = {}; - ret = function(context, options) { - // Create a new partials stack frame prior to exec. - let original = container.partials; - container.partials = extend({}, original, props.partials); - let ret = fn(context, options); - container.partials = original; - return ret; - }; - } +export default function (instance) { + instance.registerDecorator( + 'inline', + function (fn, props, container, options) { + let ret = fn; + if (!props.partials) { + props.partials = {}; + ret = function (context, options) { + // Create a new partials stack frame prior to exec. + let original = container.partials; + container.partials = extend({}, original, props.partials); + let ret = fn(context, options); + container.partials = original; + return ret; + }; + } - props.partials[options.args[0]] = options.fn; + props.partials[options.args[0]] = options.fn; - return ret; - }); + return ret; + } + ); } diff --git a/lib/handlebars/helpers/block-helper-missing.js b/lib/handlebars/helpers/block-helper-missing.js index c16ad1a64..c9e1b7501 100644 --- a/lib/handlebars/helpers/block-helper-missing.js +++ b/lib/handlebars/helpers/block-helper-missing.js @@ -1,7 +1,7 @@ import { isArray } from '../utils'; -export default function(instance) { - instance.registerHelper('blockHelperMissing', function(context, options) { +export default function (instance) { + instance.registerHelper('blockHelperMissing', function (context, options) { let inverse = options.inverse, fn = options.fn; diff --git a/lib/handlebars/helpers/each.js b/lib/handlebars/helpers/each.js index 0c7e6263e..309c2786f 100644 --- a/lib/handlebars/helpers/each.js +++ b/lib/handlebars/helpers/each.js @@ -1,8 +1,8 @@ import { Exception } from '@handlebars/parser'; import { createFrame, isArray, isFunction } from '../utils'; -export default function(instance) { - instance.registerHelper('each', function(context, options) { +export default function (instance) { + instance.registerHelper('each', function (context, options) { if (!options) { throw new Exception('Must pass iterator to #each'); } @@ -33,7 +33,7 @@ export default function(instance) { ret + fn(context[field], { data: data, - blockParams: [context[field], field] + blockParams: [context[field], field], }); } @@ -57,7 +57,7 @@ export default function(instance) { } else { let priorKey; - Object.keys(context).forEach(key => { + Object.keys(context).forEach((key) => { // We're running the iterations one step out of sync so we can detect // the last iteration without have to scan the object twice and create // an intermediate keys array. diff --git a/lib/handlebars/helpers/helper-missing.js b/lib/handlebars/helpers/helper-missing.js index 6daf44253..c59a3206a 100644 --- a/lib/handlebars/helpers/helper-missing.js +++ b/lib/handlebars/helpers/helper-missing.js @@ -1,7 +1,7 @@ import { Exception } from '@handlebars/parser'; -export default function(instance) { - instance.registerHelper('helperMissing', function(/* [args, ]options */) { +export default function (instance) { + instance.registerHelper('helperMissing', function (/* [args, ]options */) { if (arguments.length === 1) { // A missing field in a {{foo}} construct. return undefined; diff --git a/lib/handlebars/helpers/if.js b/lib/handlebars/helpers/if.js index 74d5dac5a..bb2f4dfaa 100644 --- a/lib/handlebars/helpers/if.js +++ b/lib/handlebars/helpers/if.js @@ -1,8 +1,8 @@ import { Exception } from '@handlebars/parser'; import { isEmpty, isFunction } from '../utils'; -export default function(instance) { - instance.registerHelper('if', function(conditional, options) { +export default function (instance) { + instance.registerHelper('if', function (conditional, options) { if (arguments.length != 2) { throw new Exception('#if requires exactly one argument'); } @@ -20,14 +20,14 @@ export default function(instance) { } }); - instance.registerHelper('unless', function(conditional, options) { + instance.registerHelper('unless', function (conditional, options) { if (arguments.length != 2) { throw new Exception('#unless requires exactly one argument'); } return instance.helpers['if'].call(this, conditional, { fn: options.inverse, inverse: options.fn, - hash: options.hash + hash: options.hash, }); }); } diff --git a/lib/handlebars/helpers/log.js b/lib/handlebars/helpers/log.js index ab0d73646..799ec6b2f 100644 --- a/lib/handlebars/helpers/log.js +++ b/lib/handlebars/helpers/log.js @@ -1,5 +1,5 @@ -export default function(instance) { - instance.registerHelper('log', function(/* message, options */) { +export default function (instance) { + instance.registerHelper('log', function (/* message, options */) { let args = [undefined], options = arguments[arguments.length - 1]; for (let i = 0; i < arguments.length - 1; i++) { diff --git a/lib/handlebars/helpers/lookup.js b/lib/handlebars/helpers/lookup.js index 5620aba32..14bcb04a2 100644 --- a/lib/handlebars/helpers/lookup.js +++ b/lib/handlebars/helpers/lookup.js @@ -1,5 +1,5 @@ -export default function(instance) { - instance.registerHelper('lookup', function(obj, field, options) { +export default function (instance) { + instance.registerHelper('lookup', function (obj, field, options) { if (!obj) { // Note for 5.0: Change to "obj == null" in 5.0 return obj; diff --git a/lib/handlebars/helpers/with.js b/lib/handlebars/helpers/with.js index 63559be5c..908477bda 100644 --- a/lib/handlebars/helpers/with.js +++ b/lib/handlebars/helpers/with.js @@ -1,8 +1,8 @@ import { Exception } from '@handlebars/parser'; import { isEmpty, isFunction } from '../utils'; -export default function(instance) { - instance.registerHelper('with', function(context, options) { +export default function (instance) { + instance.registerHelper('with', function (context, options) { if (arguments.length != 2) { throw new Exception('#with requires exactly one argument'); } @@ -17,7 +17,7 @@ export default function(instance) { return fn(context, { data: data, - blockParams: [context] + blockParams: [context], }); } else { return options.inverse(this); diff --git a/lib/handlebars/internal/proto-access.js b/lib/handlebars/internal/proto-access.js index 1d040c4b3..9d19c23f7 100644 --- a/lib/handlebars/internal/proto-access.js +++ b/lib/handlebars/internal/proto-access.js @@ -20,15 +20,15 @@ export function createProtoAccessControl(runtimeOptions) { defaultPropertyWhiteList, runtimeOptions.allowedProtoProperties ), - defaultValue: runtimeOptions.allowProtoPropertiesByDefault + defaultValue: runtimeOptions.allowProtoPropertiesByDefault, }, methods: { whitelist: createNewLookupObject( defaultMethodWhiteList, runtimeOptions.allowedProtoMethods ), - defaultValue: runtimeOptions.allowProtoMethodsByDefault - } + defaultValue: runtimeOptions.allowProtoMethodsByDefault, + }, }; } @@ -64,7 +64,7 @@ function logUnexpectedPropertyAccessOnce(propertyName) { } export function resetLoggedProperties() { - Object.keys(loggedProperties).forEach(propertyName => { + Object.keys(loggedProperties).forEach((propertyName) => { delete loggedProperties[propertyName]; }); } diff --git a/lib/handlebars/internal/wrapHelper.js b/lib/handlebars/internal/wrapHelper.js index cd321d57e..161cce3dc 100644 --- a/lib/handlebars/internal/wrapHelper.js +++ b/lib/handlebars/internal/wrapHelper.js @@ -4,7 +4,7 @@ export function wrapHelper(helper, transformOptionsFn) { // We try to make the wrapper least-invasive by not wrapping it, if the helper is not a function. return helper; } - let wrapper = function(/* dynamic arguments */) { + let wrapper = function (/* dynamic arguments */) { const options = arguments[arguments.length - 1]; arguments[arguments.length - 1] = transformOptionsFn(options); return helper.apply(this, arguments); diff --git a/lib/handlebars/logger.js b/lib/handlebars/logger.js index bc411b250..a7022ef04 100644 --- a/lib/handlebars/logger.js +++ b/lib/handlebars/logger.js @@ -5,7 +5,7 @@ let logger = { level: 'info', // Maps a given level value to the `methodMap` indexes above. - lookupLevel: function(level) { + lookupLevel: function (level) { if (typeof level === 'string') { let levelMap = indexOf(logger.methodMap, level.toLowerCase()); if (levelMap >= 0) { @@ -19,7 +19,7 @@ let logger = { }, // Can be overridden in the host environment - log: function(level, ...message) { + log: function (level, ...message) { level = logger.lookupLevel(level); if ( @@ -33,7 +33,7 @@ let logger = { } console[method](...message); // eslint-disable-line no-console } - } + }, }; export default logger; diff --git a/lib/handlebars/no-conflict.js b/lib/handlebars/no-conflict.js index 5a6db3e9a..c19ced36a 100644 --- a/lib/handlebars/no-conflict.js +++ b/lib/handlebars/no-conflict.js @@ -1,9 +1,9 @@ -export default function(Handlebars) { +export default function (Handlebars) { /* istanbul ignore next */ let root = typeof global !== 'undefined' ? global : window, // eslint-disable-line no-undef $Handlebars = root.Handlebars; /* istanbul ignore next */ - Handlebars.noConflict = function() { + Handlebars.noConflict = function () { if (root.Handlebars === Handlebars) { root.Handlebars = $Handlebars; } diff --git a/lib/handlebars/runtime.js b/lib/handlebars/runtime.js index 999f2cb8c..1c7cc4ccb 100644 --- a/lib/handlebars/runtime.js +++ b/lib/handlebars/runtime.js @@ -4,13 +4,13 @@ import { COMPILER_REVISION, createFrame, LAST_COMPATIBLE_COMPILER_REVISION, - REVISION_CHANGES + REVISION_CHANGES, } from './base'; import { moveHelperToHooks } from './helpers'; import { wrapHelper } from './internal/wrapHelper'; import { createProtoAccessControl, - resultIsAllowed + resultIsAllowed, } from './internal/proto-access'; export function checkRevision(compilerInfo) { @@ -73,7 +73,7 @@ export function template(templateSpec, env) { let extendedOptions = Utils.extend({}, options, { hooks: this.hooks, - protoAccessControl: this.protoAccessControl + protoAccessControl: this.protoAccessControl, }); let result = env.VM.invokePartial.call( @@ -115,15 +115,15 @@ export function template(templateSpec, env) { // Just add water let container = { - strict: function(obj, name, loc) { + strict: function (obj, name, loc) { if (!obj || !(name in obj)) { throw new Exception('"' + name + '" not defined in ' + obj, { - loc: loc + loc: loc, }); } return container.lookupProperty(obj, name); }, - lookupProperty: function(parent, propertyName) { + lookupProperty: function (parent, propertyName) { let result = parent[propertyName]; if (result == null) { return result; @@ -137,7 +137,7 @@ export function template(templateSpec, env) { } return undefined; }, - lookup: function(depths, name) { + lookup: function (depths, name) { const len = depths.length; for (let i = 0; i < len; i++) { let result = depths[i] && container.lookupProperty(depths[i], name); @@ -146,21 +146,21 @@ export function template(templateSpec, env) { } } }, - lambda: function(current, context) { + lambda: function (current, context) { return typeof current === 'function' ? current.call(context) : current; }, escapeExpression: Utils.escapeExpression, invokePartial: invokePartialWrapper, - fn: function(i) { + fn: function (i) { let ret = templateSpec[i]; ret.decorator = templateSpec[i + '_d']; return ret; }, programs: [], - program: function(i, data, declaredBlockParams, blockParams, depths) { + program: function (i, data, declaredBlockParams, blockParams, depths) { let programWrapper = this.programs[i], fn = this.fn(i); if (data || depths || blockParams || declaredBlockParams) { @@ -179,13 +179,13 @@ export function template(templateSpec, env) { return programWrapper; }, - data: function(value, depth) { + data: function (value, depth) { while (value && depth--) { value = value._parent; } return value; }, - mergeIfNeeded: function(param, common) { + mergeIfNeeded: function (param, common) { let obj = param || common; if (param && common && param !== common) { @@ -198,7 +198,7 @@ export function template(templateSpec, env) { nullContext: Object.seal({}), noop: env.VM.noop, - compilerInfo: templateSpec.compiler + compilerInfo: templateSpec.compiler, }; function ret(context, options = {}) { @@ -412,7 +412,7 @@ function executeDecorators(fn, prog, container, depths, data, blockParams) { } function wrapHelpersToPassLookupProperty(mergedHelpers, container) { - Object.keys(mergedHelpers).forEach(helperName => { + Object.keys(mergedHelpers).forEach((helperName) => { let helper = mergedHelpers[helperName]; mergedHelpers[helperName] = passLookupPropertyOption(helper, container); }); @@ -420,7 +420,7 @@ function wrapHelpersToPassLookupProperty(mergedHelpers, container) { function passLookupPropertyOption(helper, container) { const lookupProperty = container.lookupProperty; - return wrapHelper(helper, options => { + return wrapHelper(helper, (options) => { return Utils.extend({ lookupProperty }, options); }); } diff --git a/lib/handlebars/safe-string.js b/lib/handlebars/safe-string.js index 468019421..c655eeea1 100644 --- a/lib/handlebars/safe-string.js +++ b/lib/handlebars/safe-string.js @@ -3,7 +3,7 @@ function SafeString(string) { this.string = string; } -SafeString.prototype.toString = SafeString.prototype.toHTML = function() { +SafeString.prototype.toString = SafeString.prototype.toHTML = function () { return '' + this.string; }; diff --git a/lib/handlebars/utils.js b/lib/handlebars/utils.js index 2fa2b6b97..c1ca0d440 100644 --- a/lib/handlebars/utils.js +++ b/lib/handlebars/utils.js @@ -5,7 +5,7 @@ const escape = { '"': '"', "'": ''', '`': '`', - '=': '=' + '=': '=', }; const badChars = /[&<>"'`=]/g, @@ -38,7 +38,7 @@ export function isFunction(value) { /* istanbul ignore next */ export const isArray = Array.isArray || - function(value) { + function (value) { return value && typeof value === 'object' ? toString.call(value) === '[object Array]' : false; diff --git a/lib/precompiler.js b/lib/precompiler.js index ab6056932..2b3fb69df 100644 --- a/lib/precompiler.js +++ b/lib/precompiler.js @@ -6,12 +6,12 @@ import * as Handlebars from './handlebars'; import { basename } from 'path'; import { SourceMapConsumer, SourceNode } from 'source-map'; -module.exports.loadTemplates = function(opts, callback) { - loadStrings(opts, function(err, strings) { +module.exports.loadTemplates = function (opts, callback) { + loadStrings(opts, function (err, strings) { if (err) { callback(err); } else { - loadFiles(opts, function(err, files) { + loadFiles(opts, function (err, files) { if (err) { callback(err); } else { @@ -37,7 +37,7 @@ function loadStrings(opts, callback) { Async.map( strings, - function(string, callback) { + function (string, callback) { if (string !== '-') { callback(undefined, string); } else { @@ -45,19 +45,19 @@ function loadStrings(opts, callback) { let buffer = ''; process.stdin.setEncoding('utf8'); - process.stdin.on('data', function(chunk) { + process.stdin.on('data', function (chunk) { buffer += chunk; }); - process.stdin.on('end', function() { + process.stdin.on('end', function () { callback(undefined, buffer); }); } }, - function(err, strings) { + function (err, strings) { strings = strings.map((string, index) => ({ name: names[index], path: names[index], - source: string + source: string, })); callback(err, strings); } @@ -68,20 +68,23 @@ function loadFiles(opts, callback) { // Build file extension pattern let extension = (opts.extension || 'handlebars').replace( /[\\^$*+?.():=!|{}\-[\]]/g, - function(arg) { + function (arg) { return '\\' + arg; } ); extension = new RegExp('\\.' + extension + '$'); let ret = [], - queue = (opts.files || []).map(template => ({ template, root: opts.root })); + queue = (opts.files || []).map((template) => ({ + template, + root: opts.root, + })); Async.whilst( () => queue.length, - function(callback) { + function (callback) { let { template: path, root } = queue.shift(); - fs.stat(path, function(err, stat) { + fs.stat(path, function (err, stat) { if (err) { return callback( new Handlebars.Exception(`Unable to open template file "${path}"`) @@ -91,12 +94,12 @@ function loadFiles(opts, callback) { if (stat.isDirectory()) { opts.hasDirectory = true; - fs.readdir(path, function(err, children) { + fs.readdir(path, function (err, children) { /* istanbul ignore next : Race condition that being too lazy to test */ if (err) { return callback(err); } - children.forEach(function(file) { + children.forEach(function (file) { let childPath = path + '/' + file; if ( @@ -110,7 +113,7 @@ function loadFiles(opts, callback) { callback(); }); } else { - fs.readFile(path, 'utf8', function(err, data) { + fs.readFile(path, 'utf8', function (err, data) { /* istanbul ignore next : Race condition that being too lazy to test */ if (err) { return callback(err); @@ -132,7 +135,7 @@ function loadFiles(opts, callback) { ret.push({ path: path, name: name, - source: data + source: data, }); callback(); @@ -140,7 +143,7 @@ function loadFiles(opts, callback) { } }); }, - function(err) { + function (err) { if (err) { callback(err); } else { @@ -150,7 +153,7 @@ function loadFiles(opts, callback) { ); } -module.exports.cli = function(opts) { +module.exports.cli = function (opts) { if (opts.version) { console.log(Handlebars.VERSION); return; @@ -219,10 +222,10 @@ module.exports.cli = function(opts) { output.add('{};\n'); } - opts.templates.forEach(function(template) { + opts.templates.forEach(function (template) { let options = { knownHelpers: known, - knownHelpersOnly: opts.o + knownHelpersOnly: opts.o, }; if (opts.map) { @@ -259,7 +262,7 @@ module.exports.cli = function(opts) { template.name, "'] = template(", precompiled, - ');\n' + ');\n', ]); } }); @@ -335,7 +338,7 @@ function minify(output, sourceMapFile) { return require('uglify-js').minify(output.code, { sourceMap: { content: output.map, - url: sourceMapFile - } + url: sourceMapFile, + }, }); } diff --git a/nyc.config.js b/nyc.config.js index 3f52f089e..b71608a8a 100644 --- a/nyc.config.js +++ b/nyc.config.js @@ -5,5 +5,5 @@ module.exports = { functions: 100, statements: 100, exclude: ['**/spec/**'], - reporter: 'html' + reporter: 'html', }; diff --git a/package-lock.json b/package-lock.json index 28e43d4f7..da1138f4c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -51,7 +51,7 @@ "mock-stdin": "^0.3.0", "mustache": "^2.1.3", "nyc": "^14.1.1", - "prettier": "^1.19.1", + "prettier": "^2.7.1", "semver": "^5.0.1", "sinon": "^7.5.0", "typescript": "^3.4.3", @@ -11268,15 +11268,18 @@ } }, "node_modules/prettier": { - "version": "1.19.1", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-1.19.1.tgz", - "integrity": "sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew==", + "version": "2.7.1", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.7.1.tgz", + "integrity": "sha512-ujppO+MkdPqoVINuDFDRLClm7D78qbDt0/NR+wp5FqEZOoTNAjPHWj17QRhu7geIHJfcNhRk1XVQmF8Bp3ye+g==", "dev": true, "bin": { "prettier": "bin-prettier.js" }, "engines": { - "node": ">=4" + "node": ">=10.13.0" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" } }, "node_modules/pretty-bytes": { @@ -23629,9 +23632,9 @@ "dev": true }, "prettier": { - "version": "1.19.1", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-1.19.1.tgz", - "integrity": "sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew==", + "version": "2.7.1", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.7.1.tgz", + "integrity": "sha512-ujppO+MkdPqoVINuDFDRLClm7D78qbDt0/NR+wp5FqEZOoTNAjPHWj17QRhu7geIHJfcNhRk1XVQmF8Bp3ye+g==", "dev": true }, "pretty-bytes": { diff --git a/package.json b/package.json index 9505c2370..7351ee8da 100644 --- a/package.json +++ b/package.json @@ -62,7 +62,7 @@ "mock-stdin": "^0.3.0", "mustache": "^2.1.3", "nyc": "^14.1.1", - "prettier": "^1.19.1", + "prettier": "^2.7.1", "semver": "^5.0.1", "sinon": "^7.5.0", "typescript": "^3.4.3", diff --git a/prettier.config.js b/prettier.config.js index 6593a6b7d..70767b70e 100644 --- a/prettier.config.js +++ b/prettier.config.js @@ -1,5 +1,5 @@ module.exports = { tabWidth: 2, semi: true, - singleQuote: true + singleQuote: true, }; diff --git a/spec/.eslintrc.js b/spec/.eslintrc.js index 99d292fea..9eaea1c47 100644 --- a/spec/.eslintrc.js +++ b/spec/.eslintrc.js @@ -22,16 +22,16 @@ module.exports = { strictEqual: true, define: true, expect: true, - chai: true + chai: true, }, env: { - mocha: true + mocha: true, }, rules: { // Disabling for tests, for now. 'no-path-concat': 'off', 'no-var': 'off', - 'dot-notation': 'off' - } + 'dot-notation': 'off', + }, }; diff --git a/spec/ast.js b/spec/ast.js index d31752048..beb38a464 100644 --- a/spec/ast.js +++ b/spec/ast.js @@ -1,14 +1,14 @@ -describe('ast', function() { +describe('ast', function () { if (!Handlebars.AST) { return; } var AST = Handlebars.AST; - describe('BlockStatement', function() { - it('should throw on mustache mismatch', function() { + describe('BlockStatement', function () { + it('should throw on mustache mismatch', function () { shouldThrow( - function() { + function () { handlebarsEnv.parse('\n {{#foo}}{{/bar}}'); }, Handlebars.Exception, @@ -17,14 +17,14 @@ describe('ast', function() { }); }); - describe('helpers', function() { - describe('#helperExpression', function() { - it('should handle mustache statements', function() { + describe('helpers', function () { + describe('#helperExpression', function () { + it('should handle mustache statements', function () { equals( AST.helpers.helperExpression({ type: 'MustacheStatement', params: [], - hash: undefined + hash: undefined, }), false ); @@ -32,7 +32,7 @@ describe('ast', function() { AST.helpers.helperExpression({ type: 'MustacheStatement', params: [1], - hash: undefined + hash: undefined, }), true ); @@ -40,17 +40,17 @@ describe('ast', function() { AST.helpers.helperExpression({ type: 'MustacheStatement', params: [], - hash: {} + hash: {}, }), true ); }); - it('should handle block statements', function() { + it('should handle block statements', function () { equals( AST.helpers.helperExpression({ type: 'BlockStatement', params: [], - hash: undefined + hash: undefined, }), false ); @@ -58,7 +58,7 @@ describe('ast', function() { AST.helpers.helperExpression({ type: 'BlockStatement', params: [1], - hash: undefined + hash: undefined, }), true ); @@ -66,15 +66,15 @@ describe('ast', function() { AST.helpers.helperExpression({ type: 'BlockStatement', params: [], - hash: {} + hash: {}, }), true ); }); - it('should handle subexpressions', function() { + it('should handle subexpressions', function () { equals(AST.helpers.helperExpression({ type: 'SubExpression' }), true); }); - it('should work with non-helper nodes', function() { + it('should work with non-helper nodes', function () { equals(AST.helpers.helperExpression({ type: 'Program' }), false); equals( @@ -107,7 +107,7 @@ describe('ast', function() { }); }); - describe('Line Numbers', function() { + describe('Line Numbers', function () { var ast, body; function testColumns(node, firstLine, lastLine, firstColumn, lastColumn) { @@ -120,59 +120,59 @@ describe('ast', function() { /* eslint-disable no-multi-spaces */ ast = Handlebars.parse( 'line 1 {{line1Token}}\n' + // 1 - ' line 2 {{line2token}}\n' + // 2 - ' line 3 {{#blockHelperOnLine3}}\n' + // 3 - 'line 4{{line4token}}\n' + // 4 - 'line5{{else}}\n' + // 5 - '{{line6Token}}\n' + // 6 - '{{/blockHelperOnLine3}}\n' + // 7 - '{{#open}}\n' + // 8 - '{{else inverse}}\n' + // 9 - '{{else}}\n' + // 10 + ' line 2 {{line2token}}\n' + // 2 + ' line 3 {{#blockHelperOnLine3}}\n' + // 3 + 'line 4{{line4token}}\n' + // 4 + 'line5{{else}}\n' + // 5 + '{{line6Token}}\n' + // 6 + '{{/blockHelperOnLine3}}\n' + // 7 + '{{#open}}\n' + // 8 + '{{else inverse}}\n' + // 9 + '{{else}}\n' + // 10 '{{/open}}' ); // 11 /* eslint-enable no-multi-spaces */ body = ast.body; - it('gets ContentNode line numbers', function() { + it('gets ContentNode line numbers', function () { var contentNode = body[0]; testColumns(contentNode, 1, 1, 0, 7); }); - it('gets MustacheStatement line numbers', function() { + it('gets MustacheStatement line numbers', function () { var mustacheNode = body[1]; testColumns(mustacheNode, 1, 1, 7, 21); }); - it('gets line numbers correct when newlines appear', function() { + it('gets line numbers correct when newlines appear', function () { testColumns(body[2], 1, 2, 21, 8); }); - it('gets MustacheStatement line numbers correct across newlines', function() { + it('gets MustacheStatement line numbers correct across newlines', function () { var secondMustacheStatement = body[3]; testColumns(secondMustacheStatement, 2, 2, 8, 22); }); - it('gets the block helper information correct', function() { + it('gets the block helper information correct', function () { var blockHelperNode = body[5]; testColumns(blockHelperNode, 3, 7, 8, 23); }); - it('correctly records the line numbers the program of a block helper', function() { + it('correctly records the line numbers the program of a block helper', function () { var blockHelperNode = body[5], program = blockHelperNode.program; testColumns(program, 3, 5, 31, 5); }); - it('correctly records the line numbers of an inverse of a block helper', function() { + it('correctly records the line numbers of an inverse of a block helper', function () { var blockHelperNode = body[5], inverse = blockHelperNode.inverse; testColumns(inverse, 5, 7, 13, 0); }); - it('correctly records the line number of chained inverses', function() { + it('correctly records the line number of chained inverses', function () { var chainInverseNode = body[7]; testColumns(chainInverseNode.program, 8, 9, 9, 0); diff --git a/spec/basic.js b/spec/basic.js index 4c7afb706..b7f4f637f 100644 --- a/spec/basic.js +++ b/spec/basic.js @@ -1,17 +1,15 @@ global.handlebarsEnv = null; -beforeEach(function() { +beforeEach(function () { global.handlebarsEnv = Handlebars.create(); }); -describe('basic context', function() { - it('most basic', function() { - expectTemplate('{{foo}}') - .withInput({ foo: 'foo' }) - .toCompileTo('foo'); +describe('basic context', function () { + it('most basic', function () { + expectTemplate('{{foo}}').withInput({ foo: 'foo' }).toCompileTo('foo'); }); - it('escaping', function() { + it('escaping', function () { expectTemplate('\\{{foo}}') .withInput({ foo: 'food' }) .toCompileTo('{{foo}}'); @@ -33,23 +31,21 @@ describe('basic context', function() { .toCompileTo('\\\\ food'); }); - it('compiling with a basic context', function() { + it('compiling with a basic context', function () { expectTemplate('Goodbye\n{{cruel}}\n{{world}}!') .withInput({ cruel: 'cruel', - world: 'world' + world: 'world', }) .withMessage('It works if all the required keys are provided') .toCompileTo('Goodbye\ncruel\nworld!'); }); - it('compiling with a string context', function() { - expectTemplate('{{.}}{{length}}') - .withInput('bye') - .toCompileTo('bye3'); + it('compiling with a string context', function () { + expectTemplate('{{.}}{{length}}').withInput('bye').toCompileTo('bye3'); }); - it('compiling with an undefined context', function() { + it('compiling with an undefined context', function () { expectTemplate('Goodbye\n{{cruel}}\n{{world.bar}}!') .withInput(undefined) .toCompileTo('Goodbye\n\n!'); @@ -59,11 +55,11 @@ describe('basic context', function() { .toCompileTo('Goodbye'); }); - it('comments', function() { + it('comments', function () { expectTemplate('{{! Goodbye}}Goodbye\n{{cruel}}\n{{world}}!') .withInput({ cruel: 'cruel', - world: 'world' + world: 'world', }) .withMessage('comments are ignored') .toCompileTo('Goodbye\ncruel\nworld!'); @@ -87,12 +83,12 @@ describe('basic context', function() { ); }); - it('boolean', function() { + it('boolean', function () { var string = '{{#goodbye}}GOODBYE {{/goodbye}}cruel {{world}}!'; expectTemplate(string) .withInput({ goodbye: true, - world: 'world' + world: 'world', }) .withMessage('booleans show the contents when true') .toCompileTo('GOODBYE cruel world!'); @@ -100,41 +96,37 @@ describe('basic context', function() { expectTemplate(string) .withInput({ goodbye: false, - world: 'world' + world: 'world', }) .withMessage('booleans do not show the contents when false') .toCompileTo('cruel world!'); }); - it('zeros', function() { + it('zeros', function () { expectTemplate('num1: {{num1}}, num2: {{num2}}') .withInput({ num1: 42, - num2: 0 + num2: 0, }) .toCompileTo('num1: 42, num2: 0'); - expectTemplate('num: {{.}}') - .withInput(0) - .toCompileTo('num: 0'); + expectTemplate('num: {{.}}').withInput(0).toCompileTo('num: 0'); expectTemplate('num: {{num1/num2}}') .withInput({ num1: { num2: 0 } }) .toCompileTo('num: 0'); }); - it('false', function() { + it('false', function () { /* eslint-disable no-new-wrappers */ expectTemplate('val1: {{val1}}, val2: {{val2}}') .withInput({ val1: false, - val2: new Boolean(false) + val2: new Boolean(false), }) .toCompileTo('val1: false, val2: false'); - expectTemplate('val: {{.}}') - .withInput(false) - .toCompileTo('val: false'); + expectTemplate('val: {{.}}').withInput(false).toCompileTo('val: false'); expectTemplate('val: {{val1/val2}}') .withInput({ val1: { val2: false } }) @@ -143,7 +135,7 @@ describe('basic context', function() { expectTemplate('val1: {{{val1}}}, val2: {{{val2}}}') .withInput({ val1: false, - val2: new Boolean(false) + val2: new Boolean(false), }) .toCompileTo('val1: false, val2: false'); @@ -153,10 +145,10 @@ describe('basic context', function() { /* eslint-enable */ }); - it('should handle undefined and null', function() { + it('should handle undefined and null', function () { expectTemplate('{{awesome undefined null}}') .withInput({ - awesome: function(_undefined, _null, options) { + awesome: function (_undefined, _null, options) { return ( (_undefined === undefined) + ' ' + @@ -164,34 +156,34 @@ describe('basic context', function() { ' ' + typeof options ); - } + }, }) .toCompileTo('true true object'); expectTemplate('{{undefined}}') .withInput({ - undefined: function() { + undefined: function () { return 'undefined!'; - } + }, }) .toCompileTo('undefined!'); expectTemplate('{{null}}') .withInput({ - null: function() { + null: function () { return 'null!'; - } + }, }) .toCompileTo('null!'); }); - it('newlines', function() { + it('newlines', function () { expectTemplate("Alan's\nTest").toCompileTo("Alan's\nTest"); expectTemplate("Alan's\rTest").toCompileTo("Alan's\rTest"); }); - it('escaping text', function() { + it('escaping text', function () { expectTemplate("Awesome's") .withMessage( "text is escaped so that it doesn't get caught on single quotes" @@ -216,7 +208,7 @@ describe('basic context', function() { .toCompileTo(" ' ' "); }); - it('escaping expressions', function() { + it('escaping expressions', function () { expectTemplate('{{{awesome}}}') .withInput({ awesome: "&'\\<>" }) .withMessage("expressions with 3 handlebars aren't escaped") @@ -238,140 +230,140 @@ describe('basic context', function() { .toCompileTo('Escaped, <b> looks like: <b>'); }); - it("functions returning safestrings shouldn't be escaped", function() { + it("functions returning safestrings shouldn't be escaped", function () { expectTemplate('{{awesome}}') .withInput({ - awesome: function() { + awesome: function () { return new Handlebars.SafeString("&'\\<>"); - } + }, }) .withMessage("functions returning safestrings aren't escaped") .toCompileTo("&'\\<>"); }); - it('functions', function() { + it('functions', function () { expectTemplate('{{awesome}}') .withInput({ - awesome: function() { + awesome: function () { return 'Awesome'; - } + }, }) .withMessage('functions are called and render their output') .toCompileTo('Awesome'); expectTemplate('{{awesome}}') .withInput({ - awesome: function() { + awesome: function () { return this.more; }, - more: 'More awesome' + more: 'More awesome', }) .withMessage('functions are bound to the context') .toCompileTo('More awesome'); }); - it('functions with context argument', function() { + it('functions with context argument', function () { expectTemplate('{{awesome frank}}') .withInput({ - awesome: function(context) { + awesome: function (context) { return context; }, - frank: 'Frank' + frank: 'Frank', }) .withMessage('functions are called with context arguments') .toCompileTo('Frank'); }); - it('pathed functions with context argument', function() { + it('pathed functions with context argument', function () { expectTemplate('{{bar.awesome frank}}') .withInput({ bar: { - awesome: function(context) { + awesome: function (context) { return context; - } + }, }, - frank: 'Frank' + frank: 'Frank', }) .withMessage('functions are called with context arguments') .toCompileTo('Frank'); }); - it('depthed functions with context argument', function() { + it('depthed functions with context argument', function () { expectTemplate('{{#with frank}}{{../awesome .}}{{/with}}') .withInput({ - awesome: function(context) { + awesome: function (context) { return context; }, - frank: 'Frank' + frank: 'Frank', }) .withMessage('functions are called with context arguments') .toCompileTo('Frank'); }); - it('block functions with context argument', function() { + it('block functions with context argument', function () { expectTemplate('{{#awesome 1}}inner {{.}}{{/awesome}}') .withInput({ - awesome: function(context, options) { + awesome: function (context, options) { return options.fn(context); - } + }, }) .withMessage('block functions are called with context and options') .toCompileTo('inner 1'); }); - it('depthed block functions with context argument', function() { + it('depthed block functions with context argument', function () { expectTemplate( '{{#with value}}{{#../awesome 1}}inner {{.}}{{/../awesome}}{{/with}}' ) .withInput({ value: true, - awesome: function(context, options) { + awesome: function (context, options) { return options.fn(context); - } + }, }) .withMessage('block functions are called with context and options') .toCompileTo('inner 1'); }); - it('block functions without context argument', function() { + it('block functions without context argument', function () { expectTemplate('{{#awesome}}inner{{/awesome}}') .withInput({ - awesome: function(options) { + awesome: function (options) { return options.fn(this); - } + }, }) .withMessage('block functions are called with options') .toCompileTo('inner'); }); - it('pathed block functions without context argument', function() { + it('pathed block functions without context argument', function () { expectTemplate('{{#foo.awesome}}inner{{/foo.awesome}}') .withInput({ foo: { - awesome: function() { + awesome: function () { return this; - } - } + }, + }, }) .withMessage('block functions are called with options') .toCompileTo('inner'); }); - it('depthed block functions without context argument', function() { + it('depthed block functions without context argument', function () { expectTemplate( '{{#with value}}{{#../awesome}}inner{{/../awesome}}{{/with}}' ) .withInput({ value: true, - awesome: function() { + awesome: function () { return this; - } + }, }) .withMessage('block functions are called with options') .toCompileTo('inner'); }); - it('paths with hyphens', function() { + it('paths with hyphens', function () { expectTemplate('{{foo-bar}}') .withInput({ 'foo-bar': 'baz' }) .withMessage('Paths can contain hyphens (-)') @@ -388,21 +380,21 @@ describe('basic context', function() { .toCompileTo('baz'); }); - it('nested paths', function() { + it('nested paths', function () { expectTemplate('Goodbye {{alan/expression}} world!') .withInput({ alan: { expression: 'beautiful' } }) .withMessage('Nested paths access nested objects') .toCompileTo('Goodbye beautiful world!'); }); - it('nested paths with empty string value', function() { + it('nested paths with empty string value', function () { expectTemplate('Goodbye {{alan/expression}} world!') .withInput({ alan: { expression: '' } }) .withMessage('Nested paths access nested objects with empty string') .toCompileTo('Goodbye world!'); }); - it('literal paths', function() { + it('literal paths', function () { expectTemplate('Goodbye {{[@alan]/expression}} world!') .withInput({ '@alan': { expression: 'beautiful' } }) .withMessage('Literal paths can be used') @@ -414,7 +406,7 @@ describe('basic context', function() { .toCompileTo('Goodbye beautiful world!'); }); - it('literal references', function() { + it('literal references', function () { expectTemplate('Goodbye {{[foo bar]}} world!') .withInput({ 'foo bar': 'beautiful' }) .toCompileTo('Goodbye beautiful world!'); @@ -440,24 +432,22 @@ describe('basic context', function() { .toCompileTo('Goodbye beautiful world!'); }); - it("that current context path ({{.}}) doesn't hit helpers", function() { + it("that current context path ({{.}}) doesn't hit helpers", function () { expectTemplate('test: {{.}}') .withInput(null) .withHelpers({ helper: 'awesome' }) .toCompileTo('test: '); }); - it('complex but empty paths', function() { + it('complex but empty paths', function () { expectTemplate('{{person/name}}') .withInput({ person: { name: null } }) .toCompileTo(''); - expectTemplate('{{person/name}}') - .withInput({ person: {} }) - .toCompileTo(''); + expectTemplate('{{person/name}}').withInput({ person: {} }).toCompileTo(''); }); - it('this keyword in paths', function() { + it('this keyword in paths', function () { expectTemplate('{{#goodbyes}}{{this}}{{/goodbyes}}') .withInput({ goodbyes: ['goodbye', 'Goodbye', 'GOODBYE'] }) .withMessage('This keyword in paths evaluates to current context') @@ -465,32 +455,30 @@ describe('basic context', function() { expectTemplate('{{#hellos}}{{this/text}}{{/hellos}}') .withInput({ - hellos: [{ text: 'hello' }, { text: 'Hello' }, { text: 'HELLO' }] + hellos: [{ text: 'hello' }, { text: 'Hello' }, { text: 'HELLO' }], }) .withMessage('This keyword evaluates in more complex paths') .toCompileTo('helloHelloHELLO'); }); - it('this keyword nested inside path', function() { + it('this keyword nested inside path', function () { expectTemplate('{{#hellos}}{{text/this/foo}}{{/hellos}}').toThrow( Error, 'Invalid path: text/this - 1:13' ); - expectTemplate('{{[this]}}') - .withInput({ this: 'bar' }) - .toCompileTo('bar'); + expectTemplate('{{[this]}}').withInput({ this: 'bar' }).toCompileTo('bar'); expectTemplate('{{text/[this]}}') .withInput({ text: { this: 'bar' } }) .toCompileTo('bar'); }); - it('this keyword in helpers', function() { + it('this keyword in helpers', function () { var helpers = { - foo: function(value) { + foo: function (value) { return 'bar ' + value; - } + }, }; expectTemplate('{{#goodbyes}}{{foo this}}{{/goodbyes}}') @@ -501,14 +489,14 @@ describe('basic context', function() { expectTemplate('{{#hellos}}{{foo this/text}}{{/hellos}}') .withInput({ - hellos: [{ text: 'hello' }, { text: 'Hello' }, { text: 'HELLO' }] + hellos: [{ text: 'hello' }, { text: 'Hello' }, { text: 'HELLO' }], }) .withHelpers(helpers) .withMessage('This keyword evaluates in more complex paths') .toCompileTo('bar hellobar Hellobar HELLO'); }); - it('this keyword nested inside helpers param', function() { + it('this keyword nested inside helpers param', function () { expectTemplate('{{#hellos}}{{foo text/this/foo}}{{/hellos}}').toThrow( Error, 'Invalid path: text/this - 1:17' @@ -516,79 +504,69 @@ describe('basic context', function() { expectTemplate('{{foo [this]}}') .withInput({ - foo: function(value) { + foo: function (value) { return value; }, - this: 'bar' + this: 'bar', }) .toCompileTo('bar'); expectTemplate('{{foo text/[this]}}') .withInput({ - foo: function(value) { + foo: function (value) { return value; }, - text: { this: 'bar' } + text: { this: 'bar' }, }) .toCompileTo('bar'); }); - it('pass string literals', function() { + it('pass string literals', function () { expectTemplate('{{"foo"}}').toCompileTo(''); - expectTemplate('{{"foo"}}') - .withInput({ foo: 'bar' }) - .toCompileTo('bar'); + expectTemplate('{{"foo"}}').withInput({ foo: 'bar' }).toCompileTo('bar'); expectTemplate('{{#"foo"}}{{.}}{{/"foo"}}') .withInput({ - foo: ['bar', 'baz'] + foo: ['bar', 'baz'], }) .toCompileTo('barbaz'); }); - it('pass number literals', function() { + it('pass number literals', function () { expectTemplate('{{12}}').toCompileTo(''); - expectTemplate('{{12}}') - .withInput({ '12': 'bar' }) - .toCompileTo('bar'); + expectTemplate('{{12}}').withInput({ 12: 'bar' }).toCompileTo('bar'); expectTemplate('{{12.34}}').toCompileTo(''); - expectTemplate('{{12.34}}') - .withInput({ '12.34': 'bar' }) - .toCompileTo('bar'); + expectTemplate('{{12.34}}').withInput({ 12.34: 'bar' }).toCompileTo('bar'); expectTemplate('{{12.34 1}}') .withInput({ - '12.34': function(arg) { + 12.34: function (arg) { return 'bar' + arg; - } + }, }) .toCompileTo('bar1'); }); - it('pass boolean literals', function() { + it('pass boolean literals', function () { expectTemplate('{{true}}').toCompileTo(''); - expectTemplate('{{true}}') - .withInput({ '': 'foo' }) - .toCompileTo(''); + expectTemplate('{{true}}').withInput({ '': 'foo' }).toCompileTo(''); - expectTemplate('{{false}}') - .withInput({ false: 'foo' }) - .toCompileTo('foo'); + expectTemplate('{{false}}').withInput({ false: 'foo' }).toCompileTo('foo'); }); - it('should handle literals in subexpression', function() { + it('should handle literals in subexpression', function () { expectTemplate('{{foo (false)}}') .withInput({ - false: function() { + false: function () { return 'bar'; - } + }, }) - .withHelper('foo', function(arg) { + .withHelper('foo', function (arg) { return arg; }) .toCompileTo('bar'); diff --git a/spec/blocks.js b/spec/blocks.js index f15655428..550e64c23 100644 --- a/spec/blocks.js +++ b/spec/blocks.js @@ -1,5 +1,5 @@ -describe('blocks', function() { - it('array', function() { +describe('blocks', function () { + it('array', function () { var string = '{{#goodbyes}}{{text}}! {{/goodbyes}}cruel {{world}}!'; expectTemplate(string) @@ -7,9 +7,9 @@ describe('blocks', function() { goodbyes: [ { text: 'goodbye' }, { text: 'Goodbye' }, - { text: 'GOODBYE' } + { text: 'GOODBYE' }, ], - world: 'world' + world: 'world', }) .withMessage('Arrays iterate over the contents when not empty') .toCompileTo('goodbye! Goodbye! GOODBYE! cruel world!'); @@ -17,13 +17,13 @@ describe('blocks', function() { expectTemplate(string) .withInput({ goodbyes: [], - world: 'world' + world: 'world', }) .withMessage('Arrays ignore the contents when empty') .toCompileTo('cruel world!'); }); - it('array without data', function() { + it('array without data', function () { expectTemplate( '{{#goodbyes}}{{text}}{{/goodbyes}} {{#goodbyes}}{{text}}{{/goodbyes}}' ) @@ -31,15 +31,15 @@ describe('blocks', function() { goodbyes: [ { text: 'goodbye' }, { text: 'Goodbye' }, - { text: 'GOODBYE' } + { text: 'GOODBYE' }, ], - world: 'world' + world: 'world', }) .withCompileOptions({ compat: false }) .toCompileTo('goodbyeGoodbyeGOODBYE goodbyeGoodbyeGOODBYE'); }); - it('array with @index', function() { + it('array with @index', function () { expectTemplate( '{{#goodbyes}}{{@index}}. {{text}}! {{/goodbyes}}cruel {{world}}!' ) @@ -47,15 +47,15 @@ describe('blocks', function() { goodbyes: [ { text: 'goodbye' }, { text: 'Goodbye' }, - { text: 'GOODBYE' } + { text: 'GOODBYE' }, ], - world: 'world' + world: 'world', }) .withMessage('The @index variable is used') .toCompileTo('0. goodbye! 1. Goodbye! 2. GOODBYE! cruel world!'); }); - it('empty block', function() { + it('empty block', function () { var string = '{{#goodbyes}}{{/goodbyes}}cruel {{world}}!'; expectTemplate(string) @@ -63,9 +63,9 @@ describe('blocks', function() { goodbyes: [ { text: 'goodbye' }, { text: 'Goodbye' }, - { text: 'GOODBYE' } + { text: 'GOODBYE' }, ], - world: 'world' + world: 'world', }) .withMessage('Arrays iterate over the contents when not empty') .toCompileTo('cruel world!'); @@ -73,21 +73,21 @@ describe('blocks', function() { expectTemplate(string) .withInput({ goodbyes: [], - world: 'world' + world: 'world', }) .withMessage('Arrays ignore the contents when empty') .toCompileTo('cruel world!'); }); - it('block with complex lookup', function() { + it('block with complex lookup', function () { expectTemplate('{{#goodbyes}}{{text}} cruel {{../name}}! {{/goodbyes}}') .withInput({ name: 'Alan', goodbyes: [ { text: 'goodbye' }, { text: 'Goodbye' }, - { text: 'GOODBYE' } - ] + { text: 'GOODBYE' }, + ], }) .withMessage( 'Templates can access variables in contexts up the stack with relative path syntax' @@ -97,37 +97,37 @@ describe('blocks', function() { ); }); - it('multiple blocks with complex lookup', function() { + it('multiple blocks with complex lookup', function () { expectTemplate('{{#goodbyes}}{{../name}}{{../name}}{{/goodbyes}}') .withInput({ name: 'Alan', goodbyes: [ { text: 'goodbye' }, { text: 'Goodbye' }, - { text: 'GOODBYE' } - ] + { text: 'GOODBYE' }, + ], }) .toCompileTo('AlanAlanAlanAlanAlanAlan'); }); - it('block with complex lookup using nested context', function() { + it('block with complex lookup using nested context', function () { expectTemplate( '{{#goodbyes}}{{text}} cruel {{foo/../name}}! {{/goodbyes}}' ).toThrow(Error); }); - it('block with deep nested complex lookup', function() { + it('block with deep nested complex lookup', function () { expectTemplate( '{{#outer}}Goodbye {{#inner}}cruel {{../sibling}} {{../../omg}}{{/inner}}{{/outer}}' ) .withInput({ omg: 'OMG!', - outer: [{ sibling: 'sad', inner: [{ text: 'goodbye' }] }] + outer: [{ sibling: 'sad', inner: [{ text: 'goodbye' }] }], }) .toCompileTo('Goodbye cruel sad OMG!'); }); - it('works with cached blocks', function() { + it('works with cached blocks', function () { expectTemplate( '{{#each person}}{{#with .}}{{first}} {{last}}{{/with}}{{/each}}' ) @@ -135,14 +135,14 @@ describe('blocks', function() { .withInput({ person: [ { first: 'Alan', last: 'Johnson' }, - { first: 'Alan', last: 'Johnson' } - ] + { first: 'Alan', last: 'Johnson' }, + ], }) .toCompileTo('Alan JohnsonAlan Johnson'); }); - describe('inverted sections', function() { - it('inverted sections with unset value', function() { + describe('inverted sections', function () { + it('inverted sections with unset value', function () { expectTemplate( '{{#goodbyes}}{{this}}{{/goodbyes}}{{^goodbyes}}Right On!{{/goodbyes}}' ) @@ -150,7 +150,7 @@ describe('blocks', function() { .toCompileTo('Right On!'); }); - it('inverted section with false value', function() { + it('inverted section with false value', function () { expectTemplate( '{{#goodbyes}}{{this}}{{/goodbyes}}{{^goodbyes}}Right On!{{/goodbyes}}' ) @@ -159,7 +159,7 @@ describe('blocks', function() { .toCompileTo('Right On!'); }); - it('inverted section with empty set', function() { + it('inverted section with empty set', function () { expectTemplate( '{{#goodbyes}}{{this}}{{/goodbyes}}{{^goodbyes}}Right On!{{/goodbyes}}' ) @@ -168,13 +168,13 @@ describe('blocks', function() { .toCompileTo('Right On!'); }); - it('block inverted sections', function() { + it('block inverted sections', function () { expectTemplate('{{#people}}{{name}}{{^}}{{none}}{{/people}}') .withInput({ none: 'No people' }) .toCompileTo('No people'); }); - it('chained inverted sections', function() { + it('chained inverted sections', function () { expectTemplate('{{#people}}{{name}}{{else if none}}{{none}}{{/people}}') .withInput({ none: 'No people' }) .toCompileTo('No people'); @@ -192,24 +192,24 @@ describe('blocks', function() { .toCompileTo('No people'); }); - it('chained inverted sections with mismatch', function() { + it('chained inverted sections with mismatch', function () { expectTemplate( '{{#people}}{{name}}{{else if none}}{{none}}{{/if}}' ).toThrow(Error); }); - it('block inverted sections with empty arrays', function() { + it('block inverted sections with empty arrays', function () { expectTemplate('{{#people}}{{name}}{{^}}{{none}}{{/people}}') .withInput({ none: 'No people', - people: [] + people: [], }) .toCompileTo('No people'); }); }); - describe('standalone sections', function() { - it('block standalone else sections', function() { + describe('standalone sections', function () { + it('block standalone else sections', function () { expectTemplate('{{#people}}\n{{name}}\n{{^}}\n{{none}}\n{{/people}}\n') .withInput({ none: 'No people' }) .toCompileTo('No people\n'); @@ -223,7 +223,7 @@ describe('blocks', function() { .toCompileTo('No people\n'); }); - it('block standalone else sections can be disabled', function() { + it('block standalone else sections can be disabled', function () { expectTemplate('{{#people}}\n{{name}}\n{{^}}\n{{none}}\n{{/people}}\n') .withInput({ none: 'No people' }) .withCompileOptions({ ignoreStandalone: true }) @@ -235,7 +235,7 @@ describe('blocks', function() { .toCompileTo('\nNo people\n\n'); }); - it('block standalone chained else sections', function() { + it('block standalone chained else sections', function () { expectTemplate( '{{#people}}\n{{name}}\n{{else if none}}\n{{none}}\n{{/people}}\n' ) @@ -249,17 +249,17 @@ describe('blocks', function() { .toCompileTo('No people\n'); }); - it('should handle nesting', function() { + it('should handle nesting', function () { expectTemplate('{{#data}}\n{{#if true}}\n{{.}}\n{{/if}}\n{{/data}}\nOK.') .withInput({ - data: [1, 3, 5] + data: [1, 3, 5], }) .toCompileTo('1\n3\n5\nOK.'); }); }); - describe('compat mode', function() { - it('block with deep recursive lookup lookup', function() { + describe('compat mode', function () { + it('block with deep recursive lookup lookup', function () { expectTemplate( '{{#outer}}Goodbye {{#inner}}cruel {{omg}}{{/inner}}{{/outer}}' ) @@ -268,108 +268,108 @@ describe('blocks', function() { .toCompileTo('Goodbye cruel OMG!'); }); - it('block with deep recursive pathed lookup', function() { + it('block with deep recursive pathed lookup', function () { expectTemplate( '{{#outer}}Goodbye {{#inner}}cruel {{omg.yes}}{{/inner}}{{/outer}}' ) .withInput({ omg: { yes: 'OMG!' }, - outer: [{ inner: [{ yes: 'no', text: 'goodbye' }] }] + outer: [{ inner: [{ yes: 'no', text: 'goodbye' }] }], }) .withCompileOptions({ compat: true }) .toCompileTo('Goodbye cruel OMG!'); }); - it('block with missed recursive lookup', function() { + it('block with missed recursive lookup', function () { expectTemplate( '{{#outer}}Goodbye {{#inner}}cruel {{omg.yes}}{{/inner}}{{/outer}}' ) .withInput({ omg: { no: 'OMG!' }, - outer: [{ inner: [{ yes: 'no', text: 'goodbye' }] }] + outer: [{ inner: [{ yes: 'no', text: 'goodbye' }] }], }) .withCompileOptions({ compat: true }) .toCompileTo('Goodbye cruel '); }); }); - describe('decorators', function() { - it('should apply mustache decorators', function() { + describe('decorators', function () { + it('should apply mustache decorators', function () { expectTemplate('{{#helper}}{{*decorator}}{{/helper}}') - .withHelper('helper', function(options) { + .withHelper('helper', function (options) { return options.fn.run; }) - .withDecorator('decorator', function(fn) { + .withDecorator('decorator', function (fn) { fn.run = 'success'; return fn; }) .toCompileTo('success'); }); - it('should apply allow undefined return', function() { + it('should apply allow undefined return', function () { expectTemplate('{{#helper}}{{*decorator}}suc{{/helper}}') - .withHelper('helper', function(options) { + .withHelper('helper', function (options) { return options.fn() + options.fn.run; }) - .withDecorator('decorator', function(fn) { + .withDecorator('decorator', function (fn) { fn.run = 'cess'; }) .toCompileTo('success'); }); - it('should apply block decorators', function() { + it('should apply block decorators', function () { expectTemplate( '{{#helper}}{{#*decorator}}success{{/decorator}}{{/helper}}' ) - .withHelper('helper', function(options) { + .withHelper('helper', function (options) { return options.fn.run; }) - .withDecorator('decorator', function(fn, props, container, options) { + .withDecorator('decorator', function (fn, props, container, options) { fn.run = options.fn(); return fn; }) .toCompileTo('success'); }); - it('should support nested decorators', function() { + it('should support nested decorators', function () { expectTemplate( '{{#helper}}{{#*decorator}}{{#*nested}}suc{{/nested}}cess{{/decorator}}{{/helper}}' ) - .withHelper('helper', function(options) { + .withHelper('helper', function (options) { return options.fn.run; }) .withDecorators({ - decorator: function(fn, props, container, options) { + decorator: function (fn, props, container, options) { fn.run = options.fn.nested + options.fn(); return fn; }, - nested: function(fn, props, container, options) { + nested: function (fn, props, container, options) { props.nested = options.fn(); - } + }, }) .toCompileTo('success'); }); - it('should apply multiple decorators', function() { + it('should apply multiple decorators', function () { expectTemplate( '{{#helper}}{{#*decorator}}suc{{/decorator}}{{#*decorator}}cess{{/decorator}}{{/helper}}' ) - .withHelper('helper', function(options) { + .withHelper('helper', function (options) { return options.fn.run; }) - .withDecorator('decorator', function(fn, props, container, options) { + .withDecorator('decorator', function (fn, props, container, options) { fn.run = (fn.run || '') + options.fn(); return fn; }) .toCompileTo('success'); }); - it('should access parent variables', function() { + it('should access parent variables', function () { expectTemplate('{{#helper}}{{*decorator foo}}{{/helper}}') - .withHelper('helper', function(options) { + .withHelper('helper', function (options) { return options.fn.run; }) - .withDecorator('decorator', function(fn, props, container, options) { + .withDecorator('decorator', function (fn, props, container, options) { fn.run = options.args; return fn; }) @@ -377,10 +377,10 @@ describe('blocks', function() { .toCompileTo('success'); }); - it('should work with root program', function() { + it('should work with root program', function () { var run; expectTemplate('{{*decorator "success"}}') - .withDecorator('decorator', function(fn, props, container, options) { + .withDecorator('decorator', function (fn, props, container, options) { equals(options.args[0], 'success'); run = true; return fn; @@ -390,10 +390,10 @@ describe('blocks', function() { equals(run, true); }); - it('should fail when accessing variables from root', function() { + it('should fail when accessing variables from root', function () { var run; expectTemplate('{{*decorator foo}}') - .withDecorator('decorator', function(fn, props, container, options) { + .withDecorator('decorator', function (fn, props, container, options) { equals(options.args[0], undefined); run = true; return fn; @@ -403,11 +403,11 @@ describe('blocks', function() { equals(run, true); }); - describe('registration', function() { - it('unregisters', function() { + describe('registration', function () { + it('unregisters', function () { handlebarsEnv.decorators = {}; - handlebarsEnv.registerDecorator('foo', function() { + handlebarsEnv.registerDecorator('foo', function () { return 'fail'; }); @@ -416,12 +416,12 @@ describe('blocks', function() { equals(handlebarsEnv.decorators.foo, undefined); }); - it('allows multiple globals', function() { + it('allows multiple globals', function () { handlebarsEnv.decorators = {}; handlebarsEnv.registerDecorator({ - foo: function() {}, - bar: function() {} + foo: function () {}, + bar: function () {}, }); equals(!!handlebarsEnv.decorators.foo, true); @@ -432,17 +432,17 @@ describe('blocks', function() { equals(handlebarsEnv.decorators.bar, undefined); }); - it('fails with multiple and args', function() { + it('fails with multiple and args', function () { shouldThrow( - function() { + function () { handlebarsEnv.registerDecorator( { - world: function() { + world: function () { return 'world!'; }, - testHelper: function() { + testHelper: function () { return 'found it!'; - } + }, }, {} ); diff --git a/spec/builtins.js b/spec/builtins.js index 825de237c..4c1efe4eb 100644 --- a/spec/builtins.js +++ b/spec/builtins.js @@ -1,12 +1,12 @@ -describe('builtin helpers', function() { - describe('#if', function() { - it('if', function() { +describe('builtin helpers', function () { + describe('#if', function () { + it('if', function () { var string = '{{#if goodbye}}GOODBYE {{/if}}cruel {{world}}!'; expectTemplate(string) .withInput({ goodbye: true, - world: 'world' + world: 'world', }) .withMessage('if with boolean argument shows the contents when true') .toCompileTo('GOODBYE cruel world!'); @@ -14,7 +14,7 @@ describe('builtin helpers', function() { expectTemplate(string) .withInput({ goodbye: 'dummy', - world: 'world' + world: 'world', }) .withMessage('if with string argument shows the contents') .toCompileTo('GOODBYE cruel world!'); @@ -22,7 +22,7 @@ describe('builtin helpers', function() { expectTemplate(string) .withInput({ goodbye: false, - world: 'world' + world: 'world', }) .withMessage( 'if with boolean argument does not show the contents when false' @@ -37,7 +37,7 @@ describe('builtin helpers', function() { expectTemplate(string) .withInput({ goodbye: ['foo'], - world: 'world' + world: 'world', }) .withMessage('if with non-empty array shows the contents') .toCompileTo('GOODBYE cruel world!'); @@ -45,7 +45,7 @@ describe('builtin helpers', function() { expectTemplate(string) .withInput({ goodbye: [], - world: 'world' + world: 'world', }) .withMessage('if with empty array does not show the contents') .toCompileTo('cruel world!'); @@ -53,7 +53,7 @@ describe('builtin helpers', function() { expectTemplate(string) .withInput({ goodbye: 0, - world: 'world' + world: 'world', }) .withMessage('if with zero does not show the contents') .toCompileTo('cruel world!'); @@ -63,21 +63,21 @@ describe('builtin helpers', function() { ) .withInput({ goodbye: 0, - world: 'world' + world: 'world', }) .withMessage('if with zero does not show the contents') .toCompileTo('GOODBYE cruel world!'); }); - it('if with function argument', function() { + it('if with function argument', function () { var string = '{{#if goodbye}}GOODBYE {{/if}}cruel {{world}}!'; expectTemplate(string) .withInput({ - goodbye: function() { + goodbye: function () { return true; }, - world: 'world' + world: 'world', }) .withMessage( 'if with function shows the contents when function returns true' @@ -86,10 +86,10 @@ describe('builtin helpers', function() { expectTemplate(string) .withInput({ - goodbye: function() { + goodbye: function () { return this.world; }, - world: 'world' + world: 'world', }) .withMessage( 'if with function shows the contents when function returns string' @@ -98,10 +98,10 @@ describe('builtin helpers', function() { expectTemplate(string) .withInput({ - goodbye: function() { + goodbye: function () { return false; }, - world: 'world' + world: 'world', }) .withMessage( 'if with function does not show the contents when returns false' @@ -110,10 +110,10 @@ describe('builtin helpers', function() { expectTemplate(string) .withInput({ - goodbye: function() { + goodbye: function () { return this.foo; }, - world: 'world' + world: 'world', }) .withMessage( 'if with function does not show the contents when returns undefined' @@ -121,61 +121,61 @@ describe('builtin helpers', function() { .toCompileTo('cruel world!'); }); - it('should not change the depth list', function() { + it('should not change the depth list', function () { expectTemplate( '{{#with foo}}{{#if goodbye}}GOODBYE cruel {{../world}}!{{/if}}{{/with}}' ) .withInput({ foo: { goodbye: true }, - world: 'world' + world: 'world', }) .toCompileTo('GOODBYE cruel world!'); }); }); - describe('#with', function() { - it('with', function() { + describe('#with', function () { + it('with', function () { expectTemplate('{{#with person}}{{first}} {{last}}{{/with}}') .withInput({ person: { first: 'Alan', - last: 'Johnson' - } + last: 'Johnson', + }, }) .toCompileTo('Alan Johnson'); }); - it('with with function argument', function() { + it('with with function argument', function () { expectTemplate('{{#with person}}{{first}} {{last}}{{/with}}') .withInput({ - person: function() { + person: function () { return { first: 'Alan', - last: 'Johnson' + last: 'Johnson', }; - } + }, }) .toCompileTo('Alan Johnson'); }); - it('with with else', function() { + it('with with else', function () { expectTemplate( '{{#with person}}Person is present{{else}}Person is not present{{/with}}' ).toCompileTo('Person is not present'); }); - it('with provides block parameter', function() { + it('with provides block parameter', function () { expectTemplate('{{#with person as |foo|}}{{foo.first}} {{last}}{{/with}}') .withInput({ person: { first: 'Alan', - last: 'Johnson' - } + last: 'Johnson', + }, }) .toCompileTo('Alan Johnson'); }); - it('works when data is disabled', function() { + it('works when data is disabled', function () { expectTemplate('{{#with person as |foo|}}{{foo.first}} {{last}}{{/with}}') .withInput({ person: { first: 'Alan', last: 'Johnson' } }) .withCompileOptions({ data: false }) @@ -183,14 +183,14 @@ describe('builtin helpers', function() { }); }); - describe('#each', function() { - beforeEach(function() { - handlebarsEnv.registerHelper('detectDataInsideEach', function(options) { + describe('#each', function () { + beforeEach(function () { + handlebarsEnv.registerHelper('detectDataInsideEach', function (options) { return options.data && options.data.exclaim; }); }); - it('each', function() { + it('each', function () { var string = '{{#each goodbyes}}{{text}}! {{/each}}cruel {{world}}!'; expectTemplate(string) @@ -198,9 +198,9 @@ describe('builtin helpers', function() { goodbyes: [ { text: 'goodbye' }, { text: 'Goodbye' }, - { text: 'GOODBYE' } + { text: 'GOODBYE' }, ], - world: 'world' + world: 'world', }) .withMessage( 'each with array argument iterates over the contents when not empty' @@ -210,21 +210,21 @@ describe('builtin helpers', function() { expectTemplate(string) .withInput({ goodbyes: [], - world: 'world' + world: 'world', }) .withMessage('each with array argument ignores the contents when empty') .toCompileTo('cruel world!'); }); - it('each without data', function() { + it('each without data', function () { expectTemplate('{{#each goodbyes}}{{text}}! {{/each}}cruel {{world}}!') .withInput({ goodbyes: [ { text: 'goodbye' }, { text: 'Goodbye' }, - { text: 'GOODBYE' } + { text: 'GOODBYE' }, ], - world: 'world' + world: 'world', }) .withRuntimeOptions({ data: false }) .withCompileOptions({ data: false }) @@ -237,13 +237,13 @@ describe('builtin helpers', function() { .toCompileTo('cruelworld'); }); - it('each without context', function() { + it('each without context', function () { expectTemplate('{{#each goodbyes}}{{text}}! {{/each}}cruel {{world}}!') .withInput(undefined) .toCompileTo('cruel !'); }); - it('each with an object and @key', function() { + it('each with an object and @key', function () { var string = '{{#each goodbyes}}{{@key}}. {{text}}! {{/each}}cruel {{world}}!'; @@ -272,12 +272,12 @@ describe('builtin helpers', function() { expectTemplate(string) .withInput({ goodbyes: {}, - world: 'world' + world: 'world', }) .toCompileTo('cruel world!'); }); - it('each with @index', function() { + it('each with @index', function () { expectTemplate( '{{#each goodbyes}}{{@index}}. {{text}}! {{/each}}cruel {{world}}!' ) @@ -285,15 +285,15 @@ describe('builtin helpers', function() { goodbyes: [ { text: 'goodbye' }, { text: 'Goodbye' }, - { text: 'GOODBYE' } + { text: 'GOODBYE' }, ], - world: 'world' + world: 'world', }) .withMessage('The @index variable is used') .toCompileTo('0. goodbye! 1. Goodbye! 2. GOODBYE! cruel world!'); }); - it('each with nested @index', function() { + it('each with nested @index', function () { expectTemplate( '{{#each goodbyes}}{{@index}}. {{text}}! {{#each ../goodbyes}}{{@index}} {{/each}}After {{@index}} {{/each}}{{@index}}cruel {{world}}!' ) @@ -301,9 +301,9 @@ describe('builtin helpers', function() { goodbyes: [ { text: 'goodbye' }, { text: 'Goodbye' }, - { text: 'GOODBYE' } + { text: 'GOODBYE' }, ], - world: 'world' + world: 'world', }) .withMessage('The @index variable is used') .toCompileTo( @@ -311,20 +311,20 @@ describe('builtin helpers', function() { ); }); - it('each with block params', function() { + it('each with block params', function () { expectTemplate( '{{#each goodbyes as |value index|}}{{index}}. {{value.text}}! {{#each ../goodbyes as |childValue childIndex|}} {{index}} {{childIndex}}{{/each}} After {{index}} {{/each}}{{index}}cruel {{world}}!' ) .withInput({ goodbyes: [{ text: 'goodbye' }, { text: 'Goodbye' }], - world: 'world' + world: 'world', }) .toCompileTo( '0. goodbye! 0 0 0 1 After 0 1. Goodbye! 1 0 1 1 After 1 cruel world!' ); }); - it('each with block params and strict compilation', function() { + it('each with block params and strict compilation', function () { expectTemplate( '{{#each goodbyes as |value index|}}{{index}}. {{value.text}}!{{/each}}' ) @@ -333,7 +333,7 @@ describe('builtin helpers', function() { .toCompileTo('0. goodbye!1. Goodbye!'); }); - it('each object with @index', function() { + it('each object with @index', function () { expectTemplate( '{{#each goodbyes}}{{@index}}. {{text}}! {{/each}}cruel {{world}}!' ) @@ -341,15 +341,15 @@ describe('builtin helpers', function() { goodbyes: { a: { text: 'goodbye' }, b: { text: 'Goodbye' }, - c: { text: 'GOODBYE' } + c: { text: 'GOODBYE' }, }, - world: 'world' + world: 'world', }) .withMessage('The @index variable is used') .toCompileTo('0. goodbye! 1. Goodbye! 2. GOODBYE! cruel world!'); }); - it('each with @first', function() { + it('each with @first', function () { expectTemplate( '{{#each goodbyes}}{{#if @first}}{{text}}! {{/if}}{{/each}}cruel {{world}}!' ) @@ -357,15 +357,15 @@ describe('builtin helpers', function() { goodbyes: [ { text: 'goodbye' }, { text: 'Goodbye' }, - { text: 'GOODBYE' } + { text: 'GOODBYE' }, ], - world: 'world' + world: 'world', }) .withMessage('The @first variable is used') .toCompileTo('goodbye! cruel world!'); }); - it('each with nested @first', function() { + it('each with nested @first', function () { expectTemplate( '{{#each goodbyes}}({{#if @first}}{{text}}! {{/if}}{{#each ../goodbyes}}{{#if @first}}{{text}}!{{/if}}{{/each}}{{#if @first}} {{text}}!{{/if}}) {{/each}}cruel {{world}}!' ) @@ -373,9 +373,9 @@ describe('builtin helpers', function() { goodbyes: [ { text: 'goodbye' }, { text: 'Goodbye' }, - { text: 'GOODBYE' } + { text: 'GOODBYE' }, ], - world: 'world' + world: 'world', }) .withMessage('The @first variable is used') .toCompileTo( @@ -383,19 +383,19 @@ describe('builtin helpers', function() { ); }); - it('each object with @first', function() { + it('each object with @first', function () { expectTemplate( '{{#each goodbyes}}{{#if @first}}{{text}}! {{/if}}{{/each}}cruel {{world}}!' ) .withInput({ goodbyes: { foo: { text: 'goodbye' }, bar: { text: 'Goodbye' } }, - world: 'world' + world: 'world', }) .withMessage('The @first variable is used') .toCompileTo('goodbye! cruel world!'); }); - it('each with @last', function() { + it('each with @last', function () { expectTemplate( '{{#each goodbyes}}{{#if @last}}{{text}}! {{/if}}{{/each}}cruel {{world}}!' ) @@ -403,27 +403,27 @@ describe('builtin helpers', function() { goodbyes: [ { text: 'goodbye' }, { text: 'Goodbye' }, - { text: 'GOODBYE' } + { text: 'GOODBYE' }, ], - world: 'world' + world: 'world', }) .withMessage('The @last variable is used') .toCompileTo('GOODBYE! cruel world!'); }); - it('each object with @last', function() { + it('each object with @last', function () { expectTemplate( '{{#each goodbyes}}{{#if @last}}{{text}}! {{/if}}{{/each}}cruel {{world}}!' ) .withInput({ goodbyes: { foo: { text: 'goodbye' }, bar: { text: 'Goodbye' } }, - world: 'world' + world: 'world', }) .withMessage('The @last variable is used') .toCompileTo('Goodbye! cruel world!'); }); - it('each with nested @last', function() { + it('each with nested @last', function () { expectTemplate( '{{#each goodbyes}}({{#if @last}}{{text}}! {{/if}}{{#each ../goodbyes}}{{#if @last}}{{text}}!{{/if}}{{/each}}{{#if @last}} {{text}}!{{/if}}) {{/each}}cruel {{world}}!' ) @@ -431,9 +431,9 @@ describe('builtin helpers', function() { goodbyes: [ { text: 'goodbye' }, { text: 'Goodbye' }, - { text: 'GOODBYE' } + { text: 'GOODBYE' }, ], - world: 'world' + world: 'world', }) .withMessage('The @last variable is used') .toCompileTo( @@ -441,19 +441,19 @@ describe('builtin helpers', function() { ); }); - it('each with function argument', function() { + it('each with function argument', function () { var string = '{{#each goodbyes}}{{text}}! {{/each}}cruel {{world}}!'; expectTemplate(string) .withInput({ - goodbyes: function() { + goodbyes: function () { return [ { text: 'goodbye' }, { text: 'Goodbye' }, - { text: 'GOODBYE' } + { text: 'GOODBYE' }, ]; }, - world: 'world' + world: 'world', }) .withMessage( 'each with array function argument iterates over the contents when not empty' @@ -463,7 +463,7 @@ describe('builtin helpers', function() { expectTemplate(string) .withInput({ goodbyes: [], - world: 'world' + world: 'world', }) .withMessage( 'each with array function argument ignores the contents when empty' @@ -471,7 +471,7 @@ describe('builtin helpers', function() { .toCompileTo('cruel world!'); }); - it('each object when last key is an empty string', function() { + it('each object when last key is an empty string', function () { expectTemplate( '{{#each goodbyes}}{{@index}}. {{text}}! {{/each}}cruel {{world}}!' ) @@ -479,15 +479,15 @@ describe('builtin helpers', function() { goodbyes: { a: { text: 'goodbye' }, b: { text: 'Goodbye' }, - '': { text: 'GOODBYE' } + '': { text: 'GOODBYE' }, }, - world: 'world' + world: 'world', }) .withMessage('Empty string key is not skipped') .toCompileTo('0. goodbye! 1. Goodbye! 2. GOODBYE! cruel world!'); }); - it('data passed to helpers', function() { + it('data passed to helpers', function () { expectTemplate( '{{#each letters}}{{this}}{{detectDataInsideEach}}{{/each}}' ) @@ -495,13 +495,13 @@ describe('builtin helpers', function() { .withMessage('should output data') .withRuntimeOptions({ data: { - exclaim: '!' - } + exclaim: '!', + }, }) .toCompileTo('a!b!c!'); }); - it('each on implicit context', function() { + it('each on implicit context', function () { expectTemplate('{{#each}}{{text}}! {{/each}}cruel world!').toThrow( handlebarsEnv.Exception, 'Must pass iterator to #each' @@ -509,12 +509,12 @@ describe('builtin helpers', function() { }); if (global.Symbol && global.Symbol.iterator) { - it('each on iterable', function() { + it('each on iterable', function () { function Iterator(arr) { this.arr = arr; this.index = 0; } - Iterator.prototype.next = function() { + Iterator.prototype.next = function () { var value = this.arr[this.index]; var done = this.index === this.arr.length; if (!done) { @@ -525,7 +525,7 @@ describe('builtin helpers', function() { function Iterable(arr) { this.arr = arr; } - Iterable.prototype[global.Symbol.iterator] = function() { + Iterable.prototype[global.Symbol.iterator] = function () { return new Iterator(this.arr); }; var string = '{{#each goodbyes}}{{text}}! {{/each}}cruel {{world}}!'; @@ -535,9 +535,9 @@ describe('builtin helpers', function() { goodbyes: new Iterable([ { text: 'goodbye' }, { text: 'Goodbye' }, - { text: 'GOODBYE' } + { text: 'GOODBYE' }, ]), - world: 'world' + world: 'world', }) .withMessage( 'each with array argument iterates over the contents when not empty' @@ -547,7 +547,7 @@ describe('builtin helpers', function() { expectTemplate(string) .withInput({ goodbyes: new Iterable([]), - world: 'world' + world: 'world', }) .withMessage( 'each with array argument ignores the contents when empty' @@ -557,27 +557,27 @@ describe('builtin helpers', function() { } }); - describe('#log', function() { + describe('#log', function () { /* eslint-disable no-console */ if (typeof console === 'undefined') { return; } var $log, $info, $error; - beforeEach(function() { + beforeEach(function () { $log = console.log; $info = console.info; $error = console.error; }); - afterEach(function() { + afterEach(function () { console.log = $log; console.info = $info; console.error = $error; }); - it('should call logger at default level', function() { + it('should call logger at default level', function () { var levelArg, logArg; - handlebarsEnv.log = function(level, arg) { + handlebarsEnv.log = function (level, arg) { levelArg = level; logArg = arg; }; @@ -590,9 +590,9 @@ describe('builtin helpers', function() { equals('whee', logArg, "should call log with 'whee'"); }); - it('should call logger at data level', function() { + it('should call logger at data level', function () { var levelArg, logArg; - handlebarsEnv.log = function(level, arg) { + handlebarsEnv.log = function (level, arg) { levelArg = level; logArg = arg; }; @@ -606,16 +606,16 @@ describe('builtin helpers', function() { equals('whee', logArg); }); - it('should output to info', function() { + it('should output to info', function () { var called; - console.info = function(info) { + console.info = function (info) { equals('whee', info); called = true; console.info = $info; console.log = $log; }; - console.log = function(log) { + console.log = function (log) { equals('whee', log); called = true; console.info = $info; @@ -628,10 +628,10 @@ describe('builtin helpers', function() { equals(true, called); }); - it('should log at data level', function() { + it('should log at data level', function () { var called; - console.error = function(log) { + console.error = function (log) { equals('whee', log); called = true; console.error = $error; @@ -645,11 +645,11 @@ describe('builtin helpers', function() { equals(true, called); }); - it('should handle missing logger', function() { + it('should handle missing logger', function () { var called = false; console.error = undefined; - console.log = function(log) { + console.log = function (log) { equals('whee', log); called = true; console.log = $log; @@ -663,10 +663,10 @@ describe('builtin helpers', function() { equals(true, called); }); - it('should handle string log levels', function() { + it('should handle string log levels', function () { var called; - console.error = function(log) { + console.error = function (log) { equals('whee', log); called = true; }; @@ -688,10 +688,10 @@ describe('builtin helpers', function() { equals(true, called); }); - it('should handle hash log levels', function() { + it('should handle hash log levels', function () { var called; - console.error = function(log) { + console.error = function (log) { equals('whee', log); called = true; }; @@ -702,13 +702,17 @@ describe('builtin helpers', function() { equals(true, called); }); - it('should handle hash log levels', function() { + it('should handle hash log levels', function () { var called = false; - console.info = console.log = console.error = console.debug = function() { - called = true; - console.info = console.log = console.error = console.debug = $log; - }; + console.info = + console.log = + console.error = + console.debug = + function () { + called = true; + console.info = console.log = console.error = console.debug = $log; + }; expectTemplate('{{log blah level="debug"}}') .withInput({ blah: 'whee' }) @@ -716,10 +720,10 @@ describe('builtin helpers', function() { equals(false, called); }); - it('should pass multiple log arguments', function() { + it('should pass multiple log arguments', function () { var called; - console.info = console.log = function(log1, log2, log3) { + console.info = console.log = function (log1, log2, log3) { equals('whee', log1); equals('foo', log2); equals(1, log3); @@ -733,31 +737,29 @@ describe('builtin helpers', function() { equals(true, called); }); - it('should pass zero log arguments', function() { + it('should pass zero log arguments', function () { var called; - console.info = console.log = function() { + console.info = console.log = function () { expect(arguments.length).to.equal(0); called = true; console.log = $log; }; - expectTemplate('{{log}}') - .withInput({ blah: 'whee' }) - .toCompileTo(''); + expectTemplate('{{log}}').withInput({ blah: 'whee' }).toCompileTo(''); expect(called).to.be.true(); }); /* eslint-enable no-console */ }); - describe('#lookup', function() { - it('should lookup arbitrary content', function() { + describe('#lookup', function () { + it('should lookup arbitrary content', function () { expectTemplate('{{#each goodbyes}}{{lookup ../data .}}{{/each}}') .withInput({ goodbyes: [0, 1], data: ['foo', 'bar'] }) .toCompileTo('foobar'); }); - it('should not fail on undefined value', function() { + it('should not fail on undefined value', function () { expectTemplate('{{#each goodbyes}}{{lookup ../bar .}}{{/each}}') .withInput({ goodbyes: [0, 1], data: ['foo', 'bar'] }) .toCompileTo(''); diff --git a/spec/compiler.js b/spec/compiler.js index 8b30ed4a1..22f5f5a29 100644 --- a/spec/compiler.js +++ b/spec/compiler.js @@ -1,15 +1,15 @@ -describe('compiler', function() { +describe('compiler', function () { if (!Handlebars.compile) { return; } - describe('#equals', function() { + describe('#equals', function () { function compile(string) { var ast = Handlebars.parse(string); return new Handlebars.Compiler().compile(ast, {}); } - it('should treat as equal', function() { + it('should treat as equal', function () { equal(compile('foo').equals(compile('foo')), true); equal(compile('{{foo}}').equals(compile('{{foo}}')), true); equal(compile('{{foo.bar}}').equals(compile('{{foo.bar}}')), true); @@ -30,7 +30,7 @@ describe('compiler', function() { true ); }); - it('should treat as not equal', function() { + it('should treat as not equal', function () { equal(compile('foo').equals(compile('bar')), false); equal(compile('{{foo}}').equals(compile('{{bar}}')), false); equal(compile('{{foo.bar}}').equals(compile('{{bar.bar}}')), false); @@ -59,17 +59,17 @@ describe('compiler', function() { }); }); - describe('#compile', function() { - it('should fail with invalid input', function() { + describe('#compile', function () { + it('should fail with invalid input', function () { shouldThrow( - function() { + function () { Handlebars.compile(null); }, Error, 'You must pass a string or Handlebars AST to Handlebars.compile. You passed null' ); shouldThrow( - function() { + function () { Handlebars.compile({}); }, Error, @@ -77,7 +77,7 @@ describe('compiler', function() { ); }); - it('should include the location in the error (row and column)', function() { + it('should include the location in the error (row and column)', function () { try { Handlebars.compile(' \n {{#if}}\n{{/def}}')(); equal( @@ -101,7 +101,7 @@ describe('compiler', function() { } }); - it('should include the location as enumerable property', function() { + it('should include the location as enumerable property', function () { try { Handlebars.compile(' \n {{#if}}\n{{/def}}')(); equal( @@ -118,30 +118,30 @@ describe('compiler', function() { } }); - it('can utilize AST instance', function() { + it('can utilize AST instance', function () { equal( Handlebars.compile({ type: 'Program', - body: [{ type: 'ContentStatement', value: 'Hello' }] + body: [{ type: 'ContentStatement', value: 'Hello' }], })(), 'Hello' ); }); - it('can pass through an empty string', function() { + it('can pass through an empty string', function () { equal(Handlebars.compile('')(), ''); }); - it('throws on desupported options', function() { + it('throws on desupported options', function () { shouldThrow( - function() { + function () { Handlebars.compile('Dudes', { trackIds: true }); }, Error, 'TrackIds and stringParams are no longer supported. See Github #1145' ); shouldThrow( - function() { + function () { Handlebars.compile('Dudes', { stringParams: true }); }, Error, @@ -149,7 +149,7 @@ describe('compiler', function() { ); }); - it('should not modify the options.data property(GH-1327)', function() { + it('should not modify the options.data property(GH-1327)', function () { var options = { data: [{ a: 'foo' }, { a: 'bar' }] }; Handlebars.compile('{{#each data}}{{@index}}:{{a}} {{/each}}', options)(); equal( @@ -158,7 +158,7 @@ describe('compiler', function() { ); }); - it('should not modify the options.knownHelpers property(GH-1327)', function() { + it('should not modify the options.knownHelpers property(GH-1327)', function () { var options = { knownHelpers: {} }; Handlebars.compile('{{#each data}}{{@index}}:{{a}} {{/each}}', options)(); equal( @@ -168,17 +168,17 @@ describe('compiler', function() { }); }); - describe('#precompile', function() { - it('should fail with invalid input', function() { + describe('#precompile', function () { + it('should fail with invalid input', function () { shouldThrow( - function() { + function () { Handlebars.precompile(null); }, Error, 'You must pass a string or Handlebars AST to Handlebars.compile. You passed null' ); shouldThrow( - function() { + function () { Handlebars.precompile({}); }, Error, @@ -186,19 +186,19 @@ describe('compiler', function() { ); }); - it('can utilize AST instance', function() { + it('can utilize AST instance', function () { equal( /return "Hello"/.test( Handlebars.precompile({ type: 'Program', - body: [{ type: 'ContentStatement', value: 'Hello' }] + body: [{ type: 'ContentStatement', value: 'Hello' }], }) ), true ); }); - it('can pass through an empty string', function() { + it('can pass through an empty string', function () { equal(/return ""/.test(Handlebars.precompile('')), true); }); }); diff --git a/spec/data.js b/spec/data.js index 676798123..5402c4f9d 100644 --- a/spec/data.js +++ b/spec/data.js @@ -1,8 +1,8 @@ -describe('data', function() { - it('passing in data to a compiled function that expects data - works with helpers', function() { +describe('data', function () { + it('passing in data to a compiled function that expects data - works with helpers', function () { expectTemplate('{{hello}}') .withCompileOptions({ data: true }) - .withHelper('hello', function(options) { + .withHelper('hello', function (options) { return options.data.adjective + ' ' + this.noun; }) .withRuntimeOptions({ data: { adjective: 'happy' } }) @@ -11,17 +11,17 @@ describe('data', function() { .toCompileTo('happy cat'); }); - it('data can be looked up via @foo', function() { + it('data can be looked up via @foo', function () { expectTemplate('{{@hello}}') .withRuntimeOptions({ data: { hello: 'hello' } }) .withMessage('@foo retrieves template data') .toCompileTo('hello'); }); - it('deep @foo triggers automatic top-level data', function() { + it('deep @foo triggers automatic top-level data', function () { var helpers = Handlebars.createFrame(handlebarsEnv.helpers); - helpers.let = function(options) { + helpers.let = function (options) { var frame = Handlebars.createFrame(options.data); for (var prop in options.hash) { @@ -41,83 +41,83 @@ describe('data', function() { .toCompileTo('Hello world'); }); - it('parameter data can be looked up via @foo', function() { + it('parameter data can be looked up via @foo', function () { expectTemplate('{{hello @world}}') .withRuntimeOptions({ data: { world: 'world' } }) - .withHelper('hello', function(noun) { + .withHelper('hello', function (noun) { return 'Hello ' + noun; }) .withMessage('@foo as a parameter retrieves template data') .toCompileTo('Hello world'); }); - it('hash values can be looked up via @foo', function() { + it('hash values can be looked up via @foo', function () { expectTemplate('{{hello noun=@world}}') .withRuntimeOptions({ data: { world: 'world' } }) - .withHelper('hello', function(options) { + .withHelper('hello', function (options) { return 'Hello ' + options.hash.noun; }) .withMessage('@foo as a parameter retrieves template data') .toCompileTo('Hello world'); }); - it('nested parameter data can be looked up via @foo.bar', function() { + it('nested parameter data can be looked up via @foo.bar', function () { expectTemplate('{{hello @world.bar}}') .withRuntimeOptions({ data: { world: { bar: 'world' } } }) - .withHelper('hello', function(noun) { + .withHelper('hello', function (noun) { return 'Hello ' + noun; }) .withMessage('@foo as a parameter retrieves template data') .toCompileTo('Hello world'); }); - it('nested parameter data does not fail with @world.bar', function() { + it('nested parameter data does not fail with @world.bar', function () { expectTemplate('{{hello @world.bar}}') .withRuntimeOptions({ data: { foo: { bar: 'world' } } }) - .withHelper('hello', function(noun) { + .withHelper('hello', function (noun) { return 'Hello ' + noun; }) .withMessage('@foo as a parameter retrieves template data') .toCompileTo('Hello undefined'); }); - it('parameter data throws when using complex scope references', function() { + it('parameter data throws when using complex scope references', function () { expectTemplate( '{{#goodbyes}}{{text}} cruel {{@foo/../name}}! {{/goodbyes}}' ).toThrow(Error); }); - it('data can be functions', function() { + it('data can be functions', function () { expectTemplate('{{@hello}}') .withRuntimeOptions({ data: { - hello: function() { + hello: function () { return 'hello'; - } - } + }, + }, }) .toCompileTo('hello'); }); - it('data can be functions with params', function() { + it('data can be functions with params', function () { expectTemplate('{{@hello "hello"}}') .withRuntimeOptions({ data: { - hello: function(arg) { + hello: function (arg) { return arg; - } - } + }, + }, }) .toCompileTo('hello'); }); - it('data is inherited downstream', function() { + it('data is inherited downstream', function () { expectTemplate( '{{#let foo=1 bar=2}}{{#let foo=bar.baz}}{{@bar}}{{@foo}}{{/let}}{{@foo}}{{/let}}' ) .withInput({ bar: { baz: 'hello world' } }) .withCompileOptions({ data: true }) - .withHelper('let', function(options) { + .withHelper('let', function (options) { var frame = Handlebars.createFrame(options.data); for (var prop in options.hash) { if (prop in options.hash) { @@ -131,11 +131,11 @@ describe('data', function() { .toCompileTo('2hello world1'); }); - it('passing in data to a compiled function that expects data - works with helpers in partials', function() { + it('passing in data to a compiled function that expects data - works with helpers in partials', function () { expectTemplate('{{>myPartial}}') .withCompileOptions({ data: true }) .withPartial('myPartial', '{{hello}}') - .withHelper('hello', function(options) { + .withHelper('hello', function (options) { return options.data.adjective + ' ' + this.noun; }) .withInput({ noun: 'cat' }) @@ -144,10 +144,10 @@ describe('data', function() { .toCompileTo('happy cat'); }); - it('passing in data to a compiled function that expects data - works with helpers and parameters', function() { + it('passing in data to a compiled function that expects data - works with helpers and parameters', function () { expectTemplate('{{hello world}}') .withCompileOptions({ data: true }) - .withHelper('hello', function(noun, options) { + .withHelper('hello', function (noun, options) { return options.data.adjective + ' ' + noun + (this.exclaim ? '!' : ''); }) .withInput({ exclaim: true, world: 'world' }) @@ -156,15 +156,15 @@ describe('data', function() { .toCompileTo('happy world!'); }); - it('passing in data to a compiled function that expects data - works with block helpers', function() { + it('passing in data to a compiled function that expects data - works with block helpers', function () { expectTemplate('{{#hello}}{{world}}{{/hello}}') .withCompileOptions({ - data: true + data: true, }) - .withHelper('hello', function(options) { + .withHelper('hello', function (options) { return options.fn(this); }) - .withHelper('world', function(options) { + .withHelper('world', function (options) { return options.data.adjective + ' world' + (this.exclaim ? '!' : ''); }) .withInput({ exclaim: true }) @@ -173,13 +173,13 @@ describe('data', function() { .toCompileTo('happy world!'); }); - it('passing in data to a compiled function that expects data - works with block helpers that use ..', function() { + it('passing in data to a compiled function that expects data - works with block helpers that use ..', function () { expectTemplate('{{#hello}}{{world ../zomg}}{{/hello}}') .withCompileOptions({ data: true }) - .withHelper('hello', function(options) { + .withHelper('hello', function (options) { return options.fn({ exclaim: '?' }); }) - .withHelper('world', function(thing, options) { + .withHelper('world', function (thing, options) { return options.data.adjective + ' ' + thing + (this.exclaim || ''); }) .withInput({ exclaim: true, zomg: 'world' }) @@ -188,13 +188,13 @@ describe('data', function() { .toCompileTo('happy world?'); }); - it('passing in data to a compiled function that expects data - data is passed to with block helpers where children use ..', function() { + it('passing in data to a compiled function that expects data - data is passed to with block helpers where children use ..', function () { expectTemplate('{{#hello}}{{world ../zomg}}{{/hello}}') .withCompileOptions({ data: true }) - .withHelper('hello', function(options) { + .withHelper('hello', function (options) { return options.data.accessData + ' ' + options.fn({ exclaim: '?' }); }) - .withHelper('world', function(thing, options) { + .withHelper('world', function (thing, options) { return options.data.adjective + ' ' + thing + (this.exclaim || ''); }) .withInput({ exclaim: true, zomg: 'world' }) @@ -203,16 +203,16 @@ describe('data', function() { .toCompileTo('#win happy world?'); }); - it('you can override inherited data when invoking a helper', function() { + it('you can override inherited data when invoking a helper', function () { expectTemplate('{{#hello}}{{world zomg}}{{/hello}}') .withCompileOptions({ data: true }) - .withHelper('hello', function(options) { + .withHelper('hello', function (options) { return options.fn( { exclaim: '?', zomg: 'world' }, { data: { adjective: 'sad' } } ); }) - .withHelper('world', function(thing, options) { + .withHelper('world', function (thing, options) { return options.data.adjective + ' ' + thing + (this.exclaim || ''); }) .withInput({ exclaim: true, zomg: 'planet' }) @@ -221,13 +221,13 @@ describe('data', function() { .toCompileTo('sad world?'); }); - it('you can override inherited data when invoking a helper with depth', function() { + it('you can override inherited data when invoking a helper with depth', function () { expectTemplate('{{#hello}}{{world ../zomg}}{{/hello}}') .withCompileOptions({ data: true }) - .withHelper('hello', function(options) { + .withHelper('hello', function (options) { return options.fn({ exclaim: '?' }, { data: { adjective: 'sad' } }); }) - .withHelper('world', function(thing, options) { + .withHelper('world', function (thing, options) { return options.data.adjective + ' ' + thing + (this.exclaim || ''); }) .withInput({ exclaim: true, zomg: 'world' }) @@ -236,8 +236,8 @@ describe('data', function() { .toCompileTo('sad world?'); }); - describe('@root', function() { - it('the root context can be looked up via @root', function() { + describe('@root', function () { + it('the root context can be looked up via @root', function () { expectTemplate('{{@root.foo}}') .withInput({ foo: 'hello' }) .withRuntimeOptions({ data: {} }) @@ -248,7 +248,7 @@ describe('data', function() { .toCompileTo('hello'); }); - it('passed root values take priority', function() { + it('passed root values take priority', function () { expectTemplate('{{@root.foo}}') .withInput({ foo: 'should not be used' }) .withRuntimeOptions({ data: { root: { foo: 'hello' } } }) @@ -256,21 +256,21 @@ describe('data', function() { }); }); - describe('nesting', function() { - it('the root context can be looked up via @root', function() { + describe('nesting', function () { + it('the root context can be looked up via @root', function () { expectTemplate( '{{#helper}}{{#helper}}{{@./depth}} {{@../depth}} {{@../../depth}}{{/helper}}{{/helper}}' ) .withInput({ foo: 'hello' }) - .withHelper('helper', function(options) { + .withHelper('helper', function (options) { var frame = Handlebars.createFrame(options.data); frame.depth = options.data.depth + 1; return options.fn(this, { data: frame }); }) .withRuntimeOptions({ data: { - depth: 0 - } + depth: 0, + }, }) .toCompileTo('2 1 0'); }); diff --git a/spec/env/browser.js b/spec/env/browser.js index 28541b776..19b21070b 100644 --- a/spec/env/browser.js +++ b/spec/env/browser.js @@ -26,13 +26,13 @@ vm.runInThisContext(distHandlebars, filename); global.CompilerContext = { browser: true, - compile: function(template, options) { + compile: function (template, options) { var templateSpec = handlebarsEnv.precompile(template, options); return handlebarsEnv.template(safeEval(templateSpec)); }, - compileWithPartial: function(template, options) { + compileWithPartial: function (template, options) { return handlebarsEnv.compile(template, options); - } + }, }; function safeEval(templateSpec) { diff --git a/spec/env/common.js b/spec/env/common.js index a122f4d6e..b32d71691 100644 --- a/spec/env/common.js +++ b/spec/env/common.js @@ -1,4 +1,4 @@ -var global = (function() { +var global = (function () { return this; })(); @@ -21,7 +21,7 @@ if (Error.captureStackTrace) { /** * @deprecated Use "expectTemplate(template)...toCompileTo(output)" instead */ -global.shouldCompileTo = function(string, hashOrArray, expected, message) { +global.shouldCompileTo = function (string, hashOrArray, expected, message) { shouldCompileToWithPartials(string, hashOrArray, false, expected, message); }; @@ -47,7 +47,7 @@ global.shouldCompileToWithPartials = function shouldCompileToWithPartials( /** * @deprecated Use "expectTemplate(template)...toCompileTo(output)" instead */ -global.compileWithPartials = function(string, hashOrArray, partials) { +global.compileWithPartials = function (string, hashOrArray, partials) { var template, ary, options; if (hashOrArray && hashOrArray.hash) { ary = [hashOrArray.hash, hashOrArray]; @@ -92,7 +92,7 @@ global.equals = global.equal = function equals(a, b, msg) { * @deprecated Use chai's expect-style API instead (`expect(actualValue).to.equal(expectedValue)`) * @see https://www.chaijs.com/api/bdd/#method_throw */ -global.shouldThrow = function(callback, type, msg) { +global.shouldThrow = function (callback, type, msg) { var failed; try { callback(); @@ -121,7 +121,7 @@ global.shouldThrow = function(callback, type, msg) { } }; -global.expectTemplate = function(templateAsString) { +global.expectTemplate = function (templateAsString) { return new HandlebarsTestBench(templateAsString); }; @@ -137,38 +137,38 @@ function HandlebarsTestBench(templateAsString) { this.runtimeOptions = {}; } -HandlebarsTestBench.prototype.withInput = function(input) { +HandlebarsTestBench.prototype.withInput = function (input) { this.input = input; return this; }; -HandlebarsTestBench.prototype.withHelper = function(name, helperFunction) { +HandlebarsTestBench.prototype.withHelper = function (name, helperFunction) { this.helpers[name] = helperFunction; return this; }; -HandlebarsTestBench.prototype.withHelpers = function(helperFunctions) { +HandlebarsTestBench.prototype.withHelpers = function (helperFunctions) { var self = this; - Object.keys(helperFunctions).forEach(function(name) { + Object.keys(helperFunctions).forEach(function (name) { self.withHelper(name, helperFunctions[name]); }); return this; }; -HandlebarsTestBench.prototype.withPartial = function(name, partialAsString) { +HandlebarsTestBench.prototype.withPartial = function (name, partialAsString) { this.partials[name] = partialAsString; return this; }; -HandlebarsTestBench.prototype.withPartials = function(partials) { +HandlebarsTestBench.prototype.withPartials = function (partials) { var self = this; - Object.keys(partials).forEach(function(name) { + Object.keys(partials).forEach(function (name) { self.withPartial(name, partials[name]); }); return this; }; -HandlebarsTestBench.prototype.withDecorator = function( +HandlebarsTestBench.prototype.withDecorator = function ( name, decoratorFunction ) { @@ -176,30 +176,30 @@ HandlebarsTestBench.prototype.withDecorator = function( return this; }; -HandlebarsTestBench.prototype.withDecorators = function(decorators) { +HandlebarsTestBench.prototype.withDecorators = function (decorators) { var self = this; - Object.keys(decorators).forEach(function(name) { + Object.keys(decorators).forEach(function (name) { self.withDecorator(name, decorators[name]); }); return this; }; -HandlebarsTestBench.prototype.withCompileOptions = function(compileOptions) { +HandlebarsTestBench.prototype.withCompileOptions = function (compileOptions) { this.compileOptions = compileOptions; return this; }; -HandlebarsTestBench.prototype.withRuntimeOptions = function(runtimeOptions) { +HandlebarsTestBench.prototype.withRuntimeOptions = function (runtimeOptions) { this.runtimeOptions = runtimeOptions; return this; }; -HandlebarsTestBench.prototype.withMessage = function(message) { +HandlebarsTestBench.prototype.withMessage = function (message) { this.message = message; return this; }; -HandlebarsTestBench.prototype.toCompileTo = function(expectedOutputAsString) { +HandlebarsTestBench.prototype.toCompileTo = function (expectedOutputAsString) { expect(this._compileAndExecute()).to.equal( expectedOutputAsString, this.message @@ -207,14 +207,14 @@ HandlebarsTestBench.prototype.toCompileTo = function(expectedOutputAsString) { }; // see chai "to.throw" (https://www.chaijs.com/api/bdd/#method_throw) -HandlebarsTestBench.prototype.toThrow = function(errorLike, errMsgMatcher) { +HandlebarsTestBench.prototype.toThrow = function (errorLike, errMsgMatcher) { var self = this; - expect(function() { + expect(function () { self._compileAndExecute(); }).to.throw(errorLike, errMsgMatcher, this.message); }; -HandlebarsTestBench.prototype._compileAndExecute = function() { +HandlebarsTestBench.prototype._compileAndExecute = function () { var compile = Object.keys(this.partials).length > 0 ? CompilerContext.compileWithPartial @@ -226,10 +226,10 @@ HandlebarsTestBench.prototype._compileAndExecute = function() { return template(this.input, combinedRuntimeOptions); }; -HandlebarsTestBench.prototype._combineRuntimeOptions = function() { +HandlebarsTestBench.prototype._combineRuntimeOptions = function () { var self = this; var combinedRuntimeOptions = {}; - Object.keys(this.runtimeOptions).forEach(function(key) { + Object.keys(this.runtimeOptions).forEach(function (key) { combinedRuntimeOptions[key] = self.runtimeOptions[key]; }); combinedRuntimeOptions.helpers = this.helpers; diff --git a/spec/env/node.js b/spec/env/node.js index 1d1cd09c8..bb96c1ecb 100644 --- a/spec/env/node.js +++ b/spec/env/node.js @@ -11,13 +11,13 @@ global.sinon = require('sinon'); global.Handlebars = require('../../lib'); global.CompilerContext = { - compile: function(template, options) { + compile: function (template, options) { var templateSpec = handlebarsEnv.precompile(template, options); return handlebarsEnv.template(safeEval(templateSpec)); }, - compileWithPartial: function(template, options) { + compileWithPartial: function (template, options) { return handlebarsEnv.compile(template, options); - } + }, }; function safeEval(templateSpec) { diff --git a/spec/env/runner.js b/spec/env/runner.js index 39c522cad..ffd0b8b21 100644 --- a/spec/env/runner.js +++ b/spec/env/runner.js @@ -15,25 +15,25 @@ if (grep === '--min') { var files = fs .readdirSync(testDir) - .filter(function(name) { + .filter(function (name) { return /.*\.js$/.test(name); }) - .map(function(name) { + .map(function (name) { return testDir + path.sep + name; }); if (global.minimizedTest) { - run('./runtime', function() { - run('./browser', function() { + run('./runtime', function () { + run('./browser', function () { /* eslint-disable no-process-exit */ process.exit(errors); /* eslint-enable no-process-exit */ }); }); } else { - run('./runtime', function() { - run('./browser', function() { - run('./node', function() { + run('./runtime', function () { + run('./browser', function () { + run('./node', function () { /* eslint-disable no-process-exit */ process.exit(errors); /* eslint-enable no-process-exit */ @@ -50,13 +50,13 @@ function run(env, callback) { mocha.grep(grep); } - files.forEach(function(name) { + files.forEach(function (name) { delete require.cache[name]; }); console.log('Running env: ' + env); require(env); - mocha.run(function(errorCount) { + mocha.run(function (errorCount) { errors += errorCount; callback(); }); diff --git a/spec/env/runtime.js b/spec/env/runtime.js index 2d5007a2e..43ea83171 100644 --- a/spec/env/runtime.js +++ b/spec/env/runtime.js @@ -29,9 +29,12 @@ var JavaScriptCompiler = require('../../dist/cjs/handlebars/compiler/javascript- global.CompilerContext = { browser: true, - compile: function(template, options) { + compile: function (template, options) { // Hack the compiler on to the environment for these specific tests - handlebarsEnv.precompile = function(precompileTemplate, precompileOptions) { + handlebarsEnv.precompile = function ( + precompileTemplate, + precompileOptions + ) { return compiler.precompile( precompileTemplate, precompileOptions, @@ -45,9 +48,9 @@ global.CompilerContext = { var templateSpec = handlebarsEnv.precompile(template, options); return handlebarsEnv.template(safeEval(templateSpec)); }, - compileWithPartial: function(template, options) { + compileWithPartial: function (template, options) { // Hack the compiler on to the environment for these specific tests - handlebarsEnv.compile = function(compileTemplate, compileOptions) { + handlebarsEnv.compile = function (compileTemplate, compileOptions) { return compiler.compile(compileTemplate, compileOptions, handlebarsEnv); }; handlebarsEnv.parse = parse; @@ -55,7 +58,7 @@ global.CompilerContext = { handlebarsEnv.JavaScriptCompiler = JavaScriptCompiler; return handlebarsEnv.compile(template, options); - } + }, }; function safeEval(templateSpec) { diff --git a/spec/helpers.js b/spec/helpers.js index 5166d58d6..bbea2bf60 100644 --- a/spec/helpers.js +++ b/spec/helpers.js @@ -1,11 +1,11 @@ -describe('helpers', function() { - it('helper with complex lookup$', function() { +describe('helpers', function () { + it('helper with complex lookup$', function () { expectTemplate('{{#goodbyes}}{{{link ../prefix}}}{{/goodbyes}}') .withInput({ prefix: '/root', - goodbyes: [{ text: 'Goodbye', url: 'goodbye' }] + goodbyes: [{ text: 'Goodbye', url: 'goodbye' }], }) - .withHelper('link', function(prefix) { + .withHelper('link', function (prefix) { return ( '' + this.text + '' ); @@ -13,47 +13,47 @@ describe('helpers', function() { .toCompileTo('Goodbye'); }); - it('helper for raw block gets raw content', function() { + it('helper for raw block gets raw content', function () { expectTemplate('{{{{raw}}}} {{test}} {{{{/raw}}}}') .withInput({ test: 'hello' }) - .withHelper('raw', function(options) { + .withHelper('raw', function (options) { return options.fn(); }) .withMessage('raw block helper gets raw content') .toCompileTo(' {{test}} '); }); - it('helper for raw block gets parameters', function() { + it('helper for raw block gets parameters', function () { expectTemplate('{{{{raw 1 2 3}}}} {{test}} {{{{/raw}}}}') .withInput({ test: 'hello' }) - .withHelper('raw', function(a, b, c, options) { + .withHelper('raw', function (a, b, c, options) { return options.fn() + a + b + c; }) .withMessage('raw block helper gets raw content') .toCompileTo(' {{test}} 123'); }); - describe('raw block parsing (with identity helper-function)', function() { + describe('raw block parsing (with identity helper-function)', function () { function runWithIdentityHelper(template, expected) { expectTemplate(template) - .withHelper('identity', function(options) { + .withHelper('identity', function (options) { return options.fn(); }) .toCompileTo(expected); } - it('helper for nested raw block gets raw content', function() { + it('helper for nested raw block gets raw content', function () { runWithIdentityHelper( '{{{{identity}}}} {{{{b}}}} {{{{/b}}}} {{{{/identity}}}}', ' {{{{b}}}} {{{{/b}}}} ' ); }); - it('helper for nested raw block works with empty content', function() { + it('helper for nested raw block works with empty content', function () { runWithIdentityHelper('{{{{identity}}}}{{{{/identity}}}}', ''); }); - xit('helper for nested raw block works if nested raw blocks are broken', function() { + xit('helper for nested raw block works if nested raw blocks are broken', function () { // This test was introduced in 4.4.4, but it was not the actual problem that lead to the patch release // The test is deactivated, because in 3.x this template cases an exception and it also does not work in 4.4.3 // If anyone can make this template work without breaking everything else, then go for it, @@ -64,23 +64,23 @@ describe('helpers', function() { ); }); - it('helper for nested raw block closes after first matching close', function() { + it('helper for nested raw block closes after first matching close', function () { runWithIdentityHelper( '{{{{identity}}}}abc{{{{/identity}}}} {{{{identity}}}}abc{{{{/identity}}}}', 'abc abc' ); }); - it('helper for nested raw block throw exception when with missing closing braces', function() { + it('helper for nested raw block throw exception when with missing closing braces', function () { var string = '{{{{a}}}} {{{{/a'; expectTemplate(string).toThrow(); }); }); - it('helper block with identical context', function() { + it('helper block with identical context', function () { expectTemplate('{{#goodbyes}}{{name}}{{/goodbyes}}') .withInput({ name: 'Alan' }) - .withHelper('goodbyes', function(options) { + .withHelper('goodbyes', function (options) { var out = ''; var byes = ['Goodbye', 'goodbye', 'GOODBYE']; for (var i = 0, j = byes.length; i < j; i++) { @@ -91,10 +91,10 @@ describe('helpers', function() { .toCompileTo('Goodbye Alan! goodbye Alan! GOODBYE Alan! '); }); - it('helper block with complex lookup expression', function() { + it('helper block with complex lookup expression', function () { expectTemplate('{{#goodbyes}}{{../name}}{{/goodbyes}}') .withInput({ name: 'Alan' }) - .withHelper('goodbyes', function(options) { + .withHelper('goodbyes', function (options) { var out = ''; var byes = ['Goodbye', 'goodbye', 'GOODBYE']; for (var i = 0, j = byes.length; i < j; i++) { @@ -105,15 +105,15 @@ describe('helpers', function() { .toCompileTo('Goodbye Alan! goodbye Alan! GOODBYE Alan! '); }); - it('helper with complex lookup and nested template', function() { + it('helper with complex lookup and nested template', function () { expectTemplate( '{{#goodbyes}}{{#link ../prefix}}{{text}}{{/link}}{{/goodbyes}}' ) .withInput({ prefix: '/root', - goodbyes: [{ text: 'Goodbye', url: 'goodbye' }] + goodbyes: [{ text: 'Goodbye', url: 'goodbye' }], }) - .withHelper('link', function(prefix, options) { + .withHelper('link', function (prefix, options) { return ( 'Goodbye'); }); - it('helper with complex lookup and nested template in VM+Compiler', function() { + it('helper with complex lookup and nested template in VM+Compiler', function () { expectTemplate( '{{#goodbyes}}{{#link ../prefix}}{{text}}{{/link}}{{/goodbyes}}' ) .withInput({ prefix: '/root', - goodbyes: [{ text: 'Goodbye', url: 'goodbye' }] + goodbyes: [{ text: 'Goodbye', url: 'goodbye' }], }) - .withHelper('link', function(prefix, options) { + .withHelper('link', function (prefix, options) { return ( 'Goodbye'); }); - it('helper returning undefined value', function() { + it('helper returning undefined value', function () { expectTemplate(' {{nothere}}') .withHelpers({ - nothere: function() {} + nothere: function () {}, }) .toCompileTo(' '); expectTemplate(' {{#nothere}}{{/nothere}}') .withHelpers({ - nothere: function() {} + nothere: function () {}, }) .toCompileTo(' '); }); - it('block helper', function() { + it('block helper', function () { expectTemplate('{{#goodbyes}}{{text}}! {{/goodbyes}}cruel {{world}}!') .withInput({ world: 'world' }) - .withHelper('goodbyes', function(options) { + .withHelper('goodbyes', function (options) { return options.fn({ text: 'GOODBYE' }); }) .withMessage('Block helper executed') .toCompileTo('GOODBYE! cruel world!'); }); - it('block helper staying in the same context', function() { + it('block helper staying in the same context', function () { expectTemplate('{{#form}}
{{name}}
{{/form}}') .withInput({ name: 'Yehuda' }) - .withHelper('form', function(options) { + .withHelper('form', function (options) { return ''; }) .withMessage('Block helper executed with current context') .toCompileTo(''); }); - it('block helper should have context in this', function() { + it('block helper should have context in this', function () { function link(options) { return '' + options.fn(this) + ''; } @@ -194,8 +194,8 @@ describe('helpers', function() { .withInput({ people: [ { name: 'Alan', id: 1 }, - { name: 'Yehuda', id: 2 } - ] + { name: 'Yehuda', id: 2 }, + ], }) .withHelper('link', link) .toCompileTo( @@ -203,48 +203,48 @@ describe('helpers', function() { ); }); - it('block helper for undefined value', function() { + it('block helper for undefined value', function () { expectTemplate("{{#empty}}shouldn't render{{/empty}}").toCompileTo(''); }); - it('block helper passing a new context', function() { + it('block helper passing a new context', function () { expectTemplate('{{#form yehuda}}{{name}}
{{/form}}') .withInput({ yehuda: { name: 'Yehuda' } }) - .withHelper('form', function(context, options) { + .withHelper('form', function (context, options) { return ''; }) .withMessage('Context variable resolved') .toCompileTo(''); }); - it('block helper passing a complex path context', function() { + it('block helper passing a complex path context', function () { expectTemplate('{{#form yehuda/cat}}{{name}}
{{/form}}') .withInput({ yehuda: { name: 'Yehuda', cat: { name: 'Harold' } } }) - .withHelper('form', function(context, options) { + .withHelper('form', function (context, options) { return ''; }) .withMessage('Complex path variable resolved') .toCompileTo(''); }); - it('nested block helpers', function() { + it('nested block helpers', function () { expectTemplate( '{{#form yehuda}}{{name}}
{{#link}}Hello{{/link}}{{/form}}' ) .withInput({ - yehuda: { name: 'Yehuda' } + yehuda: { name: 'Yehuda' }, }) - .withHelper('link', function(options) { + .withHelper('link', function (options) { return '' + options.fn(this) + ''; }) - .withHelper('form', function(context, options) { + .withHelper('form', function (context, options) { return ''; }) .withMessage('Both blocks executed') .toCompileTo(''); }); - it('block helper inverted sections', function() { + it('block helper inverted sections', function () { var string = "{{#list people}}{{name}}{{^}}Nobody's here{{/list}}"; function list(context, options) { if (context.length > 0) { @@ -278,24 +278,24 @@ describe('helpers', function() { expectTemplate('{{#list people}}Hello{{^}}{{message}}{{/list}}') .withInput({ people: [], - message: "Nobody's here" + message: "Nobody's here", }) .withHelpers({ list: list }) .withMessage('the context of an inverse is the parent of the block') .toCompileTo('Nobody's here
'); }); - it('pathed lambas with parameters', function() { + it('pathed lambas with parameters', function () { var hash = { - helper: function() { + helper: function () { return 'winning'; - } + }, }; hash.hash = hash; var helpers = { - './helper': function() { + './helper': function () { return 'fail'; - } + }, }; expectTemplate('{{./helper 1}}') @@ -309,14 +309,14 @@ describe('helpers', function() { .toCompileTo('winning'); }); - describe('helpers hash', function() { - it('providing a helpers hash', function() { + describe('helpers hash', function () { + it('providing a helpers hash', function () { expectTemplate('Goodbye {{cruel}} {{world}}!') .withInput({ cruel: 'cruel' }) .withHelpers({ - world: function() { + world: function () { return 'world'; - } + }, }) .withMessage('helpers hash is available') .toCompileTo('Goodbye cruel world!'); @@ -324,21 +324,21 @@ describe('helpers', function() { expectTemplate('Goodbye {{#iter}}{{cruel}} {{world}}{{/iter}}!') .withInput({ iter: [{ cruel: 'cruel' }] }) .withHelpers({ - world: function() { + world: function () { return 'world'; - } + }, }) .withMessage('helpers hash is available inside other blocks') .toCompileTo('Goodbye cruel world!'); }); - it('in cases of conflict, helpers win', function() { + it('in cases of conflict, helpers win', function () { expectTemplate('{{{lookup}}}') .withInput({ lookup: 'Explicit' }) .withHelpers({ - lookup: function() { + lookup: function () { return 'helpers'; - } + }, }) .withMessage('helpers hash has precedence escaped expansion') .toCompileTo('helpers'); @@ -346,28 +346,28 @@ describe('helpers', function() { expectTemplate('{{lookup}}') .withInput({ lookup: 'Explicit' }) .withHelpers({ - lookup: function() { + lookup: function () { return 'helpers'; - } + }, }) .withMessage('helpers hash has precedence simple expansion') .toCompileTo('helpers'); }); - it('the helpers hash is available is nested contexts', function() { + it('the helpers hash is available is nested contexts', function () { expectTemplate('{{#outer}}{{#inner}}{{helper}}{{/inner}}{{/outer}}') .withInput({ outer: { inner: { unused: [] } } }) .withHelpers({ - helper: function() { + helper: function () { return 'helper'; - } + }, }) .withMessage('helpers hash is available in nested contexts.') .toCompileTo('helper'); }); - it('the helper hash should augment the global hash', function() { - handlebarsEnv.registerHelper('test_helper', function() { + it('the helper hash should augment the global hash', function () { + handlebarsEnv.registerHelper('test_helper', function () { return 'found it!'; }); @@ -376,37 +376,37 @@ describe('helpers', function() { ) .withInput({ cruel: 'cruel' }) .withHelpers({ - world: function() { + world: function () { return 'world!'; - } + }, }) .toCompileTo('found it! Goodbye cruel world!!'); }); }); - describe('registration', function() { - it('unregisters', function() { + describe('registration', function () { + it('unregisters', function () { handlebarsEnv.helpers = {}; - handlebarsEnv.registerHelper('foo', function() { + handlebarsEnv.registerHelper('foo', function () { return 'fail'; }); handlebarsEnv.unregisterHelper('foo'); equals(handlebarsEnv.helpers.foo, undefined); }); - it('allows multiple globals', function() { + it('allows multiple globals', function () { var helpers = handlebarsEnv.helpers; handlebarsEnv.helpers = {}; handlebarsEnv.registerHelper({ if: helpers['if'], - world: function() { + world: function () { return 'world!'; }, - testHelper: function() { + testHelper: function () { return 'found it!'; - } + }, }); expectTemplate( @@ -416,17 +416,17 @@ describe('helpers', function() { .toCompileTo('found it! Goodbye cruel world!!'); }); - it('fails with multiple and args', function() { + it('fails with multiple and args', function () { shouldThrow( - function() { + function () { handlebarsEnv.registerHelper( { - world: function() { + world: function () { return 'world!'; }, - testHelper: function() { + testHelper: function () { return 'found it!'; - } + }, }, {} ); @@ -437,9 +437,9 @@ describe('helpers', function() { }); }); - it('decimal number literals work', function() { + it('decimal number literals work', function () { expectTemplate('Message: {{hello -1.2 1.2}}') - .withHelper('hello', function(times, times2) { + .withHelper('hello', function (times, times2) { if (typeof times !== 'number') { times = 'NaN'; } @@ -452,9 +452,9 @@ describe('helpers', function() { .toCompileTo('Message: Hello -1.2 1.2 times'); }); - it('negative number literals work', function() { + it('negative number literals work', function () { expectTemplate('Message: {{hello -12}}') - .withHelper('hello', function(times) { + .withHelper('hello', function (times) { if (typeof times !== 'number') { times = 'NaN'; } @@ -464,10 +464,10 @@ describe('helpers', function() { .toCompileTo('Message: Hello -12 times'); }); - describe('String literal parameters', function() { - it('simple literals work', function() { + describe('String literal parameters', function () { + it('simple literals work', function () { expectTemplate('Message: {{hello "world" 12 true false}}') - .withHelper('hello', function(param, times, bool1, bool2) { + .withHelper('hello', function (param, times, bool1, bool2) { if (typeof times !== 'number') { times = 'NaN'; } @@ -485,22 +485,22 @@ describe('helpers', function() { .toCompileTo('Message: Hello world 12 times: true false'); }); - it('using a quote in the middle of a parameter raises an error', function() { + it('using a quote in the middle of a parameter raises an error', function () { expectTemplate('Message: {{hello wo"rld"}}').toThrow(Error); }); - it('escaping a String is possible', function() { + it('escaping a String is possible', function () { expectTemplate('Message: {{{hello "\\"world\\""}}}') - .withHelper('hello', function(param) { + .withHelper('hello', function (param) { return 'Hello ' + param; }) .withMessage('template with an escaped String literal') .toCompileTo('Message: Hello "world"'); }); - it("it works with ' marks", function() { + it("it works with ' marks", function () { expectTemplate('Message: {{{hello "Alan\'s world"}}}') - .withHelper('hello', function(param) { + .withHelper('hello', function (param) { return 'Hello ' + param; }) .withMessage("template with a ' mark") @@ -508,9 +508,9 @@ describe('helpers', function() { }); }); - it('negative number literals work', function() { + it('negative number literals work', function () { expectTemplate('Message: {{hello -12}}') - .withHelper('hello', function(times) { + .withHelper('hello', function (times) { if (typeof times !== 'number') { times = 'NaN'; } @@ -520,23 +520,23 @@ describe('helpers', function() { .toCompileTo('Message: Hello -12 times'); }); - describe('multiple parameters', function() { - it('simple multi-params work', function() { + describe('multiple parameters', function () { + it('simple multi-params work', function () { expectTemplate('Message: {{goodbye cruel world}}') .withInput({ cruel: 'cruel', world: 'world' }) - .withHelper('goodbye', function(cruel, world) { + .withHelper('goodbye', function (cruel, world) { return 'Goodbye ' + cruel + ' ' + world; }) .withMessage('regular helpers with multiple params') .toCompileTo('Message: Goodbye cruel world'); }); - it('block multi-params work', function() { + it('block multi-params work', function () { expectTemplate( 'Message: {{#goodbye cruel world}}{{greeting}} {{adj}} {{noun}}{{/goodbye}}' ) .withInput({ cruel: 'cruel', world: 'world' }) - .withHelper('goodbye', function(cruel, world, options) { + .withHelper('goodbye', function (cruel, world, options) { return options.fn({ greeting: 'Goodbye', adj: cruel, noun: world }); }) .withMessage('block helpers with multiple params') @@ -544,10 +544,10 @@ describe('helpers', function() { }); }); - describe('hash', function() { - it('helpers can take an optional hash', function() { + describe('hash', function () { + it('helpers can take an optional hash', function () { expectTemplate('{{goodbye cruel="CRUEL" world="WORLD" times=12}}') - .withHelper('goodbye', function(options) { + .withHelper('goodbye', function (options) { return ( 'GOODBYE ' + options.hash.cruel + @@ -562,7 +562,7 @@ describe('helpers', function() { .toCompileTo('GOODBYE CRUEL WORLD 12 TIMES'); }); - it('helpers can take an optional hash with booleans', function() { + it('helpers can take an optional hash with booleans', function () { function goodbye(options) { if (options.hash.print === true) { return 'GOODBYE ' + options.hash.cruel + ' ' + options.hash.world; @@ -584,9 +584,9 @@ describe('helpers', function() { .toCompileTo('NOT PRINTING'); }); - it('block helpers can take an optional hash', function() { + it('block helpers can take an optional hash', function () { expectTemplate('{{#goodbye cruel="CRUEL" times=12}}world{{/goodbye}}') - .withHelper('goodbye', function(options) { + .withHelper('goodbye', function (options) { return ( 'GOODBYE ' + options.hash.cruel + @@ -601,9 +601,9 @@ describe('helpers', function() { .toCompileTo('GOODBYE CRUEL world 12 TIMES'); }); - it('block helpers can take an optional hash with single quoted stings', function() { + it('block helpers can take an optional hash with single quoted stings', function () { expectTemplate('{{#goodbye cruel="CRUEL" times=12}}world{{/goodbye}}') - .withHelper('goodbye', function(options) { + .withHelper('goodbye', function (options) { return ( 'GOODBYE ' + options.hash.cruel + @@ -618,7 +618,7 @@ describe('helpers', function() { .toCompileTo('GOODBYE CRUEL world 12 TIMES'); }); - it('block helpers can take an optional hash with booleans', function() { + it('block helpers can take an optional hash with booleans', function () { function goodbye(options) { if (options.hash.print === true) { return 'GOODBYE ' + options.hash.cruel + ' ' + options.fn(this); @@ -641,17 +641,17 @@ describe('helpers', function() { }); }); - describe('helperMissing', function() { - it('if a context is not found, helperMissing is used', function() { + describe('helperMissing', function () { + it('if a context is not found, helperMissing is used', function () { expectTemplate('{{hello}} {{link_to world}}').toThrow( /Missing helper: "link_to"/ ); }); - it('if a context is not found, custom helperMissing is used', function() { + it('if a context is not found, custom helperMissing is used', function () { expectTemplate('{{hello}} {{link_to world}}') .withInput({ hello: 'Hello', world: 'world' }) - .withHelper('helperMissing', function(mesg, options) { + .withHelper('helperMissing', function (mesg, options) { if (options.name === 'link_to') { return new Handlebars.SafeString('' + mesg + ''); } @@ -659,10 +659,10 @@ describe('helpers', function() { .toCompileTo('Hello world'); }); - it('if a value is not found, custom helperMissing is used', function() { + it('if a value is not found, custom helperMissing is used', function () { expectTemplate('{{hello}} {{link_to}}') .withInput({ hello: 'Hello', world: 'world' }) - .withHelper('helperMissing', function(options) { + .withHelper('helperMissing', function (options) { if (options.name === 'link_to') { return new Handlebars.SafeString('winning'); } @@ -671,175 +671,175 @@ describe('helpers', function() { }); }); - describe('knownHelpers', function() { - it('Known helper should render helper', function() { + describe('knownHelpers', function () { + it('Known helper should render helper', function () { expectTemplate('{{hello}}') .withCompileOptions({ - knownHelpers: { hello: true } + knownHelpers: { hello: true }, }) - .withHelper('hello', function() { + .withHelper('hello', function () { return 'foo'; }) .toCompileTo('foo'); }); - it('Unknown helper in knownHelpers only mode should be passed as undefined', function() { + it('Unknown helper in knownHelpers only mode should be passed as undefined', function () { expectTemplate('{{typeof hello}}') .withCompileOptions({ knownHelpers: { typeof: true }, - knownHelpersOnly: true + knownHelpersOnly: true, }) - .withHelper('typeof', function(arg) { + .withHelper('typeof', function (arg) { return typeof arg; }) - .withHelper('hello', function() { + .withHelper('hello', function () { return 'foo'; }) .toCompileTo('undefined'); }); - it('Builtin helpers available in knownHelpers only mode', function() { + it('Builtin helpers available in knownHelpers only mode', function () { expectTemplate('{{#unless foo}}bar{{/unless}}') .withCompileOptions({ - knownHelpersOnly: true + knownHelpersOnly: true, }) .toCompileTo('bar'); }); - it('Field lookup works in knownHelpers only mode', function() { + it('Field lookup works in knownHelpers only mode', function () { expectTemplate('{{foo}}') .withCompileOptions({ - knownHelpersOnly: true + knownHelpersOnly: true, }) .withInput({ foo: 'bar' }) .toCompileTo('bar'); }); - it('Conditional blocks work in knownHelpers only mode', function() { + it('Conditional blocks work in knownHelpers only mode', function () { expectTemplate('{{#foo}}bar{{/foo}}') .withCompileOptions({ - knownHelpersOnly: true + knownHelpersOnly: true, }) .withInput({ foo: 'baz' }) .toCompileTo('bar'); }); - it('Invert blocks work in knownHelpers only mode', function() { + it('Invert blocks work in knownHelpers only mode', function () { expectTemplate('{{^foo}}bar{{/foo}}') .withCompileOptions({ - knownHelpersOnly: true + knownHelpersOnly: true, }) .withInput({ foo: false }) .toCompileTo('bar'); }); - it('Functions are bound to the context in knownHelpers only mode', function() { + it('Functions are bound to the context in knownHelpers only mode', function () { expectTemplate('{{foo}}') .withCompileOptions({ - knownHelpersOnly: true + knownHelpersOnly: true, }) .withInput({ - foo: function() { + foo: function () { return this.bar; }, - bar: 'bar' + bar: 'bar', }) .toCompileTo('bar'); }); - it('Unknown helper call in knownHelpers only mode should throw', function() { + it('Unknown helper call in knownHelpers only mode should throw', function () { expectTemplate('{{typeof hello}}') .withCompileOptions({ knownHelpersOnly: true }) .toThrow(Error); }); }); - describe('blockHelperMissing', function() { - it('lambdas are resolved by blockHelperMissing, not handlebars proper', function() { + describe('blockHelperMissing', function () { + it('lambdas are resolved by blockHelperMissing, not handlebars proper', function () { expectTemplate('{{#truthy}}yep{{/truthy}}') .withInput({ - truthy: function() { + truthy: function () { return true; - } + }, }) .toCompileTo('yep'); }); - it('lambdas resolved by blockHelperMissing are bound to the context', function() { + it('lambdas resolved by blockHelperMissing are bound to the context', function () { expectTemplate('{{#truthy}}yep{{/truthy}}') .withInput({ - truthy: function() { + truthy: function () { return this.truthiness(); }, - truthiness: function() { + truthiness: function () { return false; - } + }, }) .toCompileTo(''); }); }); - describe('name field', function() { + describe('name field', function () { var helpers = { - blockHelperMissing: function() { + blockHelperMissing: function () { return 'missing: ' + arguments[arguments.length - 1].name; }, - helperMissing: function() { + helperMissing: function () { return 'helper missing: ' + arguments[arguments.length - 1].name; }, - helper: function() { + helper: function () { return 'ran: ' + arguments[arguments.length - 1].name; - } + }, }; - it('should include in ambiguous mustache calls', function() { + it('should include in ambiguous mustache calls', function () { expectTemplate('{{helper}}') .withHelpers(helpers) .toCompileTo('ran: helper'); }); - it('should include in helper mustache calls', function() { + it('should include in helper mustache calls', function () { expectTemplate('{{helper 1}}') .withHelpers(helpers) .toCompileTo('ran: helper'); }); - it('should include in ambiguous block calls', function() { + it('should include in ambiguous block calls', function () { expectTemplate('{{#helper}}{{/helper}}') .withHelpers(helpers) .toCompileTo('ran: helper'); }); - it('should include in simple block calls', function() { + it('should include in simple block calls', function () { expectTemplate('{{#./helper}}{{/./helper}}') .withHelpers(helpers) .toCompileTo('missing: ./helper'); }); - it('should include in helper block calls', function() { + it('should include in helper block calls', function () { expectTemplate('{{#helper 1}}{{/helper}}') .withHelpers(helpers) .toCompileTo('ran: helper'); }); - it('should include in known helper calls', function() { + it('should include in known helper calls', function () { expectTemplate('{{helper}}') .withCompileOptions({ knownHelpers: { helper: true }, - knownHelpersOnly: true + knownHelpersOnly: true, }) .withHelpers(helpers) .toCompileTo('ran: helper'); }); - it('should include full id', function() { + it('should include full id', function () { expectTemplate('{{#foo.helper}}{{/foo.helper}}') .withInput({ foo: {} }) .withHelpers(helpers) .toCompileTo('missing: foo.helper'); }); - it('should include full id if a hash is passed', function() { + it('should include full id if a hash is passed', function () { expectTemplate('{{#foo.helper bar=baz}}{{/foo.helper}}') .withInput({ foo: {} }) .withHelpers(helpers) @@ -847,136 +847,136 @@ describe('helpers', function() { }); }); - describe('name conflicts', function() { - it('helpers take precedence over same-named context properties', function() { + describe('name conflicts', function () { + it('helpers take precedence over same-named context properties', function () { expectTemplate('{{goodbye}} {{cruel world}}') - .withHelper('goodbye', function() { + .withHelper('goodbye', function () { return this.goodbye.toUpperCase(); }) - .withHelper('cruel', function(world) { + .withHelper('cruel', function (world) { return 'cruel ' + world.toUpperCase(); }) .withInput({ goodbye: 'goodbye', - world: 'world' + world: 'world', }) .withMessage('Helper executed') .toCompileTo('GOODBYE cruel WORLD'); }); - it('helpers take precedence over same-named context properties$', function() { + it('helpers take precedence over same-named context properties$', function () { expectTemplate('{{#goodbye}} {{cruel world}}{{/goodbye}}') - .withHelper('goodbye', function(options) { + .withHelper('goodbye', function (options) { return this.goodbye.toUpperCase() + options.fn(this); }) - .withHelper('cruel', function(world) { + .withHelper('cruel', function (world) { return 'cruel ' + world.toUpperCase(); }) .withInput({ goodbye: 'goodbye', - world: 'world' + world: 'world', }) .withMessage('Helper executed') .toCompileTo('GOODBYE cruel WORLD'); }); - it('Scoped names take precedence over helpers', function() { + it('Scoped names take precedence over helpers', function () { expectTemplate('{{this.goodbye}} {{cruel world}} {{cruel this.goodbye}}') - .withHelper('goodbye', function() { + .withHelper('goodbye', function () { return this.goodbye.toUpperCase(); }) - .withHelper('cruel', function(world) { + .withHelper('cruel', function (world) { return 'cruel ' + world.toUpperCase(); }) .withInput({ goodbye: 'goodbye', - world: 'world' + world: 'world', }) .withMessage('Helper not executed') .toCompileTo('goodbye cruel WORLD cruel GOODBYE'); }); - it('Scoped names take precedence over block helpers', function() { + it('Scoped names take precedence over block helpers', function () { expectTemplate( '{{#goodbye}} {{cruel world}}{{/goodbye}} {{this.goodbye}}' ) - .withHelper('goodbye', function(options) { + .withHelper('goodbye', function (options) { return this.goodbye.toUpperCase() + options.fn(this); }) - .withHelper('cruel', function(world) { + .withHelper('cruel', function (world) { return 'cruel ' + world.toUpperCase(); }) .withInput({ goodbye: 'goodbye', - world: 'world' + world: 'world', }) .withMessage('Helper executed') .toCompileTo('GOODBYE cruel WORLD goodbye'); }); }); - describe('block params', function() { - it('should take presedence over context values', function() { + describe('block params', function () { + it('should take presedence over context values', function () { expectTemplate('{{#goodbyes as |value|}}{{value}}{{/goodbyes}}{{value}}') .withInput({ value: 'foo' }) - .withHelper('goodbyes', function(options) { + .withHelper('goodbyes', function (options) { equals(options.fn.blockParams, 1); return options.fn({ value: 'bar' }, { blockParams: [1, 2] }); }) .toCompileTo('1foo'); }); - it('should take presedence over helper values', function() { + it('should take presedence over helper values', function () { expectTemplate('{{#goodbyes as |value|}}{{value}}{{/goodbyes}}{{value}}') - .withHelper('value', function() { + .withHelper('value', function () { return 'foo'; }) - .withHelper('goodbyes', function(options) { + .withHelper('goodbyes', function (options) { equals(options.fn.blockParams, 1); return options.fn({}, { blockParams: [1, 2] }); }) .toCompileTo('1foo'); }); - it('should not take presedence over pathed values', function() { + it('should not take presedence over pathed values', function () { expectTemplate( '{{#goodbyes as |value|}}{{./value}}{{/goodbyes}}{{value}}' ) .withInput({ value: 'bar' }) - .withHelper('value', function() { + .withHelper('value', function () { return 'foo'; }) - .withHelper('goodbyes', function(options) { + .withHelper('goodbyes', function (options) { equals(options.fn.blockParams, 1); return options.fn(this, { blockParams: [1, 2] }); }) .toCompileTo('barfoo'); }); - it('should take presednece over parent block params', function() { + it('should take presednece over parent block params', function () { var value = 1; expectTemplate( '{{#goodbyes as |value|}}{{#goodbyes}}{{value}}{{#goodbyes as |value|}}{{value}}{{/goodbyes}}{{/goodbyes}}{{/goodbyes}}{{value}}' ) .withInput({ value: 'foo' }) - .withHelper('goodbyes', function(options) { + .withHelper('goodbyes', function (options) { return options.fn( { value: 'bar' }, { blockParams: - options.fn.blockParams === 1 ? [value++, value++] : undefined + options.fn.blockParams === 1 ? [value++, value++] : undefined, } ); }) .toCompileTo('13foo'); }); - it('should allow block params on chained helpers', function() { + it('should allow block params on chained helpers', function () { expectTemplate( '{{#if bar}}{{else goodbyes as |value|}}{{value}}{{/if}}{{value}}' ) .withInput({ value: 'foo' }) - .withHelper('goodbyes', function(options) { + .withHelper('goodbyes', function (options) { equals(options.fn.blockParams, 1); return options.fn({ value: 'bar' }, { blockParams: [1, 2] }); }) @@ -984,58 +984,58 @@ describe('helpers', function() { }); }); - describe('built-in helpers malformed arguments ', function() { - it('if helper - too few arguments', function() { + describe('built-in helpers malformed arguments ', function () { + it('if helper - too few arguments', function () { expectTemplate('{{#if}}{{/if}}').toThrow( /#if requires exactly one argument/ ); }); - it('if helper - too many arguments, string', function() { + it('if helper - too many arguments, string', function () { expectTemplate('{{#if test "string"}}{{/if}}').toThrow( /#if requires exactly one argument/ ); }); - it('if helper - too many arguments, undefined', function() { + it('if helper - too many arguments, undefined', function () { expectTemplate('{{#if test undefined}}{{/if}}').toThrow( /#if requires exactly one argument/ ); }); - it('if helper - too many arguments, null', function() { + it('if helper - too many arguments, null', function () { expectTemplate('{{#if test null}}{{/if}}').toThrow( /#if requires exactly one argument/ ); }); - it('unless helper - too few arguments', function() { + it('unless helper - too few arguments', function () { expectTemplate('{{#unless}}{{/unless}}').toThrow( /#unless requires exactly one argument/ ); }); - it('unless helper - too many arguments', function() { + it('unless helper - too many arguments', function () { expectTemplate('{{#unless test null}}{{/unless}}').toThrow( /#unless requires exactly one argument/ ); }); - it('with helper - too few arguments', function() { + it('with helper - too few arguments', function () { expectTemplate('{{#with}}{{/with}}').toThrow( /#with requires exactly one argument/ ); }); - it('with helper - too many arguments', function() { + it('with helper - too many arguments', function () { expectTemplate('{{#with test "string"}}{{/with}}').toThrow( /#with requires exactly one argument/ ); }); }); - describe('the lookupProperty-option', function() { - it('should be passed to custom helpers', function() { + describe('the lookupProperty-option', function () { + it('should be passed to custom helpers', function () { expectTemplate('{{testHelper}}') .withHelper('testHelper', function testHelper(options) { return options.lookupProperty(this, 'testProperty'); diff --git a/spec/javascript-compiler.js b/spec/javascript-compiler.js index ed2dc8c56..41d8e74b5 100644 --- a/spec/javascript-compiler.js +++ b/spec/javascript-compiler.js @@ -1,19 +1,19 @@ -describe('javascript-compiler api', function() { +describe('javascript-compiler api', function () { if (!Handlebars.JavaScriptCompiler) { return; } - describe('#nameLookup', function() { + describe('#nameLookup', function () { var $superName; - beforeEach(function() { + beforeEach(function () { $superName = handlebarsEnv.JavaScriptCompiler.prototype.nameLookup; }); - afterEach(function() { + afterEach(function () { handlebarsEnv.JavaScriptCompiler.prototype.nameLookup = $superName; }); - it('should allow override', function() { - handlebarsEnv.JavaScriptCompiler.prototype.nameLookup = function( + it('should allow override', function () { + handlebarsEnv.JavaScriptCompiler.prototype.nameLookup = function ( parent, name ) { @@ -28,27 +28,27 @@ describe('javascript-compiler api', function() { // Tests nameLookup dot vs. bracket behavior. Bracket is required in certain cases // to avoid errors in older browsers. - it('should handle reserved words', function() { + it('should handle reserved words', function () { expectTemplate('{{foo}} {{~null~}}') .withInput({ foo: 'food' }) .toCompileTo('food'); }); }); - describe('#compilerInfo', function() { + describe('#compilerInfo', function () { var $superCheck, $superInfo; - beforeEach(function() { + beforeEach(function () { $superCheck = handlebarsEnv.VM.checkRevision; $superInfo = handlebarsEnv.JavaScriptCompiler.prototype.compilerInfo; }); - afterEach(function() { + afterEach(function () { handlebarsEnv.VM.checkRevision = $superCheck; handlebarsEnv.JavaScriptCompiler.prototype.compilerInfo = $superInfo; }); - it('should allow compilerInfo override', function() { - handlebarsEnv.JavaScriptCompiler.prototype.compilerInfo = function() { + it('should allow compilerInfo override', function () { + handlebarsEnv.JavaScriptCompiler.prototype.compilerInfo = function () { return 'crazy'; }; - handlebarsEnv.VM.checkRevision = function(compilerInfo) { + handlebarsEnv.VM.checkRevision = function (compilerInfo) { if (compilerInfo !== 'crazy') { throw new Error("It didn't work"); } @@ -58,30 +58,32 @@ describe('javascript-compiler api', function() { .toCompileTo('food '); }); }); - describe('buffer', function() { + describe('buffer', function () { var $superAppend, $superCreate; - beforeEach(function() { + beforeEach(function () { handlebarsEnv.JavaScriptCompiler.prototype.forceBuffer = true; $superAppend = handlebarsEnv.JavaScriptCompiler.prototype.appendToBuffer; $superCreate = handlebarsEnv.JavaScriptCompiler.prototype.initializeBuffer; }); - afterEach(function() { + afterEach(function () { handlebarsEnv.JavaScriptCompiler.prototype.forceBuffer = false; handlebarsEnv.JavaScriptCompiler.prototype.appendToBuffer = $superAppend; - handlebarsEnv.JavaScriptCompiler.prototype.initializeBuffer = $superCreate; + handlebarsEnv.JavaScriptCompiler.prototype.initializeBuffer = + $superCreate; }); - it('should allow init buffer override', function() { - handlebarsEnv.JavaScriptCompiler.prototype.initializeBuffer = function() { - return this.quotedString('foo_'); - }; + it('should allow init buffer override', function () { + handlebarsEnv.JavaScriptCompiler.prototype.initializeBuffer = + function () { + return this.quotedString('foo_'); + }; expectTemplate('{{foo}} ') .withInput({ foo: 'food' }) .toCompileTo('foo_food '); }); - it('should allow append buffer override', function() { - handlebarsEnv.JavaScriptCompiler.prototype.appendToBuffer = function( + it('should allow append buffer override', function () { + handlebarsEnv.JavaScriptCompiler.prototype.appendToBuffer = function ( string ) { return $superAppend.call(this, [string, ' + "_foo"']); @@ -92,13 +94,13 @@ describe('javascript-compiler api', function() { }); }); - describe('#isValidJavaScriptVariableName', function() { + describe('#isValidJavaScriptVariableName', function () { // It is there and accessible and could be used by someone. That's why we don't remove it // it 4.x. But if we keep it, we add a test // This test should not encourage you to use the function. It is not needed any more // and might be removed in 5.0 - ['test', 'abc123', 'abc_123'].forEach(function(validVariableName) { - it("should return true for '" + validVariableName + "'", function() { + ['test', 'abc123', 'abc_123'].forEach(function (validVariableName) { + it("should return true for '" + validVariableName + "'", function () { expect( handlebarsEnv.JavaScriptCompiler.isValidJavaScriptVariableName( validVariableName @@ -106,8 +108,8 @@ describe('javascript-compiler api', function() { ).to.be.true(); }); }); - [('123test', 'abc()', 'abc.cde')].forEach(function(invalidVariableName) { - it("should return true for '" + invalidVariableName + "'", function() { + [('123test', 'abc()', 'abc.cde')].forEach(function (invalidVariableName) { + it("should return true for '" + invalidVariableName + "'", function () { expect( handlebarsEnv.JavaScriptCompiler.isValidJavaScriptVariableName( invalidVariableName diff --git a/spec/partials.js b/spec/partials.js index df092267d..5144b4242 100644 --- a/spec/partials.js +++ b/spec/partials.js @@ -1,12 +1,12 @@ -describe('partials', function() { - it('basic partials', function() { +describe('partials', function () { + it('basic partials', function () { var string = 'Dudes: {{#dudes}}{{> dude}}{{/dudes}}'; var partial = '{{name}} ({{url}}) '; var hash = { dudes: [ { name: 'Yehuda', url: 'http://yehuda' }, - { name: 'Alan', url: 'http://alan' } - ] + { name: 'Alan', url: 'http://alan' }, + ], }; expectTemplate(string) @@ -22,19 +22,19 @@ describe('partials', function() { .toCompileTo('Dudes: Yehuda (http://yehuda) Alan (http://alan) '); }); - it('dynamic partials', function() { + it('dynamic partials', function () { var string = 'Dudes: {{#dudes}}{{> (partial)}}{{/dudes}}'; var partial = '{{name}} ({{url}}) '; var hash = { dudes: [ { name: 'Yehuda', url: 'http://yehuda' }, - { name: 'Alan', url: 'http://alan' } - ] + { name: 'Alan', url: 'http://alan' }, + ], }; var helpers = { - partial: function() { + partial: function () { return 'dude'; - } + }, }; expectTemplate(string) @@ -52,41 +52,41 @@ describe('partials', function() { .toCompileTo('Dudes: Yehuda (http://yehuda) Alan (http://alan) '); }); - it('failing dynamic partials', function() { + it('failing dynamic partials', function () { expectTemplate('Dudes: {{#dudes}}{{> (partial)}}{{/dudes}}') .withInput({ dudes: [ { name: 'Yehuda', url: 'http://yehuda' }, - { name: 'Alan', url: 'http://alan' } - ] + { name: 'Alan', url: 'http://alan' }, + ], }) - .withHelper('partial', function() { + .withHelper('partial', function () { return 'missing'; }) .withPartial('dude', '{{name}} ({{url}}) ') .toThrow(Handlebars.Exception, 'The partial missing could not be found'); }); - it('partials with context', function() { + it('partials with context', function () { expectTemplate('Dudes: {{>dude dudes}}') .withInput({ dudes: [ { name: 'Yehuda', url: 'http://yehuda' }, - { name: 'Alan', url: 'http://alan' } - ] + { name: 'Alan', url: 'http://alan' }, + ], }) .withPartial('dude', '{{#this}}{{name}} ({{url}}) {{/this}}') .withMessage('Partials can be passed a context') .toCompileTo('Dudes: Yehuda (http://yehuda) Alan (http://alan) '); }); - it('partials with no context', function() { + it('partials with no context', function () { var partial = '{{name}} ({{url}}) '; var hash = { dudes: [ { name: 'Yehuda', url: 'http://yehuda' }, - { name: 'Alan', url: 'http://alan' } - ] + { name: 'Alan', url: 'http://alan' }, + ], }; expectTemplate('Dudes: {{#dudes}}{{>dude}}{{/dudes}}') @@ -102,50 +102,50 @@ describe('partials', function() { .toCompileTo('Dudes: foo () foo () '); }); - it('partials with string context', function() { + it('partials with string context', function () { expectTemplate('Dudes: {{>dude "dudes"}}') .withPartial('dude', '{{.}}') .toCompileTo('Dudes: dudes'); }); - it('partials with undefined context', function() { + it('partials with undefined context', function () { expectTemplate('Dudes: {{>dude dudes}}') .withPartial('dude', '{{foo}} Empty') .toCompileTo('Dudes: Empty'); }); - it('partials with duplicate parameters', function() { + it('partials with duplicate parameters', function () { expectTemplate('Dudes: {{>dude dudes foo bar=baz}}').toThrow( Error, 'Unsupported number of partial arguments: 2 - 1:7' ); }); - it('partials with parameters', function() { + it('partials with parameters', function () { expectTemplate('Dudes: {{#dudes}}{{> dude others=..}}{{/dudes}}') .withInput({ foo: 'bar', dudes: [ { name: 'Yehuda', url: 'http://yehuda' }, - { name: 'Alan', url: 'http://alan' } - ] + { name: 'Alan', url: 'http://alan' }, + ], }) .withPartial('dude', '{{others.foo}}{{name}} ({{url}}) ') .withMessage('Basic partials output based on current context.') .toCompileTo('Dudes: barYehuda (http://yehuda) barAlan (http://alan) '); }); - it('partial in a partial', function() { + it('partial in a partial', function () { expectTemplate('Dudes: {{#dudes}}{{>dude}}{{/dudes}}') .withInput({ dudes: [ { name: 'Yehuda', url: 'http://yehuda' }, - { name: 'Alan', url: 'http://alan' } - ] + { name: 'Alan', url: 'http://alan' }, + ], }) .withPartials({ dude: '{{name}} {{> url}} ', - url: '{{url}}' + url: '{{url}}', }) .withMessage('Partials are rendered inside of other partials') .toCompileTo( @@ -153,16 +153,16 @@ describe('partials', function() { ); }); - it('rendering undefined partial throws an exception', function() { + it('rendering undefined partial throws an exception', function () { expectTemplate('{{> whatever}}').toThrow( Handlebars.Exception, 'The partial whatever could not be found' ); }); - it('registering undefined partial throws an exception', function() { + it('registering undefined partial throws an exception', function () { shouldThrow( - function() { + function () { var undef; handlebarsEnv.registerPartial('undefined_test', undef); }, @@ -171,14 +171,14 @@ describe('partials', function() { ); }); - it('rendering template partial in vm mode throws an exception', function() { + it('rendering template partial in vm mode throws an exception', function () { expectTemplate('{{> whatever}}').toThrow( Handlebars.Exception, 'The partial whatever could not be found' ); }); - it('rendering function partial in vm mode', function() { + it('rendering function partial in vm mode', function () { function partial(context) { return context.name + ' (' + context.url + ') '; } @@ -186,15 +186,15 @@ describe('partials', function() { .withInput({ dudes: [ { name: 'Yehuda', url: 'http://yehuda' }, - { name: 'Alan', url: 'http://alan' } - ] + { name: 'Alan', url: 'http://alan' }, + ], }) .withPartial('dude', partial) .withMessage('Function partials output based in VM.') .toCompileTo('Dudes: Yehuda (http://yehuda) Alan (http://alan) '); }); - it('GH-14: a partial preceding a selector', function() { + it('GH-14: a partial preceding a selector', function () { expectTemplate('Dudes: {{>dude}} {{anotherDude}}') .withInput({ name: 'Jeepers', anotherDude: 'Creepers' }) .withPartial('dude', '{{name}}') @@ -202,7 +202,7 @@ describe('partials', function() { .toCompileTo('Dudes: Jeepers Creepers'); }); - it('Partials with slash paths', function() { + it('Partials with slash paths', function () { expectTemplate('Dudes: {{> shared/dude}}') .withInput({ name: 'Jeepers', anotherDude: 'Creepers' }) .withPartial('shared/dude', '{{name}}') @@ -210,7 +210,7 @@ describe('partials', function() { .toCompileTo('Dudes: Jeepers'); }); - it('Partials with slash and point paths', function() { + it('Partials with slash and point paths', function () { expectTemplate('Dudes: {{> shared/dude.thing}}') .withInput({ name: 'Jeepers', anotherDude: 'Creepers' }) .withPartial('shared/dude.thing', '{{name}}') @@ -218,7 +218,7 @@ describe('partials', function() { .toCompileTo('Dudes: Jeepers'); }); - it('Global Partials', function() { + it('Global Partials', function () { handlebarsEnv.registerPartial('globalTest', '{{anotherDude}}'); expectTemplate('Dudes: {{> shared/dude}} {{> globalTest}}') @@ -231,10 +231,10 @@ describe('partials', function() { equals(handlebarsEnv.partials.globalTest, undefined); }); - it('Multiple partial registration', function() { + it('Multiple partial registration', function () { handlebarsEnv.registerPartial({ 'shared/dude': '{{name}}', - globalTest: '{{anotherDude}}' + globalTest: '{{anotherDude}}', }); expectTemplate('Dudes: {{> shared/dude}} {{> globalTest}}') @@ -244,7 +244,7 @@ describe('partials', function() { .toCompileTo('Dudes: Jeepers Creepers'); }); - it('Partials with integer path', function() { + it('Partials with integer path', function () { expectTemplate('Dudes: {{> 404}}') .withInput({ name: 'Jeepers', anotherDude: 'Creepers' }) .withPartial(404, '{{name}}') @@ -252,7 +252,7 @@ describe('partials', function() { .toCompileTo('Dudes: Jeepers'); }); - it('Partials with complex path', function() { + it('Partials with complex path', function () { expectTemplate('Dudes: {{> 404/asdf?.bar}}') .withInput({ name: 'Jeepers', anotherDude: 'Creepers' }) .withPartial('404/asdf?.bar', '{{name}}') @@ -260,7 +260,7 @@ describe('partials', function() { .toCompileTo('Dudes: Jeepers'); }); - it('Partials with escaped', function() { + it('Partials with escaped', function () { expectTemplate('Dudes: {{> [+404/asdf?.bar]}}') .withInput({ name: 'Jeepers', anotherDude: 'Creepers' }) .withPartial('+404/asdf?.bar', '{{name}}') @@ -268,7 +268,7 @@ describe('partials', function() { .toCompileTo('Dudes: Jeepers'); }); - it('Partials with string', function() { + it('Partials with string', function () { expectTemplate("Dudes: {{> '+404/asdf?.bar'}}") .withInput({ name: 'Jeepers', anotherDude: 'Creepers' }) .withPartial('+404/asdf?.bar', '{{name}}') @@ -276,19 +276,19 @@ describe('partials', function() { .toCompileTo('Dudes: Jeepers'); }); - it('should handle empty partial', function() { + it('should handle empty partial', function () { expectTemplate('Dudes: {{#dudes}}{{> dude}}{{/dudes}}') .withInput({ dudes: [ { name: 'Yehuda', url: 'http://yehuda' }, - { name: 'Alan', url: 'http://alan' } - ] + { name: 'Alan', url: 'http://alan' }, + ], }) .withPartial('dude', '') .toCompileTo('Dudes: '); }); - it('throw on missing partial', function() { + it('throw on missing partial', function () { var compile = handlebarsEnv.compile; var compileWithPartial = CompilerContext.compileWithPartial; handlebarsEnv.compile = undefined; @@ -300,18 +300,18 @@ describe('partials', function() { CompilerContext.compileWithPartial = compileWithPartial; }); - describe('partial blocks', function() { - it('should render partial block as default', function() { + describe('partial blocks', function () { + it('should render partial block as default', function () { expectTemplate('{{#> dude}}success{{/dude}}').toCompileTo('success'); }); - it('should execute default block with proper context', function() { + it('should execute default block with proper context', function () { expectTemplate('{{#> dude context}}{{value}}{{/dude}}') .withInput({ context: { value: 'success' } }) .toCompileTo('success'); }); - it('should propagate block parameters to default block', function() { + it('should propagate block parameters to default block', function () { expectTemplate( '{{#with context as |me|}}{{#> dude}}{{me.value}}{{/dude}}{{/with}}' ) @@ -319,79 +319,76 @@ describe('partials', function() { .toCompileTo('success'); }); - it('should not use partial block if partial exists', function() { + it('should not use partial block if partial exists', function () { expectTemplate('{{#> dude}}fail{{/dude}}') .withPartials({ dude: 'success' }) .toCompileTo('success'); }); - it('should render block from partial', function() { + it('should render block from partial', function () { expectTemplate('{{#> dude}}success{{/dude}}') .withPartials({ dude: '{{> @partial-block }}' }) .toCompileTo('success'); }); - it('should be able to render the partial-block twice', function() { + it('should be able to render the partial-block twice', function () { expectTemplate('{{#> dude}}success{{/dude}}') .withPartials({ dude: '{{> @partial-block }} {{> @partial-block }}' }) .toCompileTo('success success'); }); - it('should render block from partial with context', function() { + it('should render block from partial with context', function () { expectTemplate('{{#> dude}}{{value}}{{/dude}}') .withInput({ context: { value: 'success' } }) .withPartials({ - dude: '{{#with context}}{{> @partial-block }}{{/with}}' + dude: '{{#with context}}{{> @partial-block }}{{/with}}', }) .toCompileTo('success'); }); - it('should be able to access the @data frame from a partial-block', function() { + it('should be able to access the @data frame from a partial-block', function () { expectTemplate('{{#> dude}}in-block: {{@root/value}}{{/dude}}') .withInput({ value: 'success' }) .withPartials({ - dude: - 'before-block: {{@root/value}} {{> @partial-block }}
'
+ dude: 'before-block: {{@root/value}} {{> @partial-block }}
',
})
.toCompileTo('before-block: success in-block: success
');
});
- it('should allow the #each-helper to be used along with partial-blocks', function() {
+ it('should allow the #each-helper to be used along with partial-blocks', function () {
expectTemplate(
'{{#> list value}}value = {{.}}{{/list}}'
)
.withInput({
- value: ['a', 'b', 'c']
+ value: ['a', 'b', 'c'],
})
.withPartials({
- list:
- '