Upgrade prettier to v2

Prettier v2 has the following breaking changes:
* enforces spaces between `function` and params
* enforces trailing commas by default
This commit is contained in:
Jakob Linskeseder
2022-10-19 22:26:53 +02:00
committed by Jay Linski
parent f6ff3bf52b
commit e534a911f3
104 changed files with 1869 additions and 1894 deletions
+5 -5
View File
@@ -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',
},
};
+42 -37
View File
@@ -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: [
@@ -88,17 +93,17 @@ module.exports = function(grunt) {
dest: 'dist/',
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',
]);
};
+19 -19
View File
@@ -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);
+2 -2
View File
@@ -2,6 +2,6 @@
module.exports = {
env: {
// Handlebars should run natively in the browser
node: false
}
node: false,
},
};
+1 -1
View File
@@ -2,7 +2,7 @@ import {
parser as Parser,
parse,
parseWithoutProcessing,
Visitor
Visitor,
} from '@handlebars/parser';
import runtime from './handlebars.runtime';
+2 -2
View File
@@ -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]';
@@ -86,7 +86,7 @@ HandlebarsEnvironment.prototype = {
*/
resetLoggedPropertyAccesses() {
resetLoggedProperties();
}
},
};
export let log = logger.log;
+2 -2
View File
@@ -23,8 +23,8 @@ let AST = {
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
+3 -3
View File
@@ -42,7 +42,7 @@ if (!SourceNode) {
},
toString: function () {
return this.src;
}
},
};
}
@@ -132,7 +132,7 @@ CodeGen.prototype = {
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]);
@@ -165,7 +165,7 @@ CodeGen.prototype = {
ret.add(']');
return ret;
}
},
};
export default CodeGen;
+4 -4
View File
@@ -65,7 +65,7 @@ Compiler.prototype = {
unless: true,
with: true,
log: true,
lookup: true
lookup: true,
},
options.knownHelpers
);
@@ -353,7 +353,7 @@ Compiler.prototype = {
this.opcodes.push({
opcode: name,
args: slice.call(arguments, 1),
loc: this.sourceNode[0].loc
loc: this.sourceNode[0].loc,
});
},
@@ -438,7 +438,7 @@ Compiler.prototype = {
return [depth, param];
}
}
}
},
};
export function precompile(input, options = {}, env) {
@@ -530,7 +530,7 @@ function transformLiteralToPath(sexpr) {
depth: 0,
parts: [literal.original + ''],
original: literal.original + '',
loc: literal.loc
loc: literal.loc,
};
}
}
+22 -22
View File
@@ -20,7 +20,7 @@ JavaScriptCompiler.prototype = {
this.aliasable('container.lookup'),
'(depths, ',
JSON.stringify(name),
')'
')',
];
},
@@ -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) {
@@ -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,7 +268,7 @@ JavaScriptCompiler.prototype = {
params.join(','),
') {\n ',
source,
'}'
'}',
]);
}
},
@@ -279,7 +279,7 @@ JavaScriptCompiler.prototype = {
sourceSeen,
bufferStart,
bufferEnd;
this.source.each(line => {
this.source.each((line) => {
if (line.appendToBuffer) {
if (bufferStart) {
line.prepend(' + ');
@@ -392,7 +392,7 @@ JavaScriptCompiler.prototype = {
current,
' = ',
this.source.functionCall(blockHelperMissing, 'call', params),
'}'
'}',
]);
},
@@ -423,7 +423,7 @@ JavaScriptCompiler.prototype = {
// Otherwise, the empty string is appended
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),
' }'
' }',
]);
}
}
@@ -457,7 +457,7 @@ JavaScriptCompiler.prototype = {
this.aliasable('container.escapeExpression'),
'(',
this.popStack(),
')'
')',
])
);
},
@@ -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.
@@ -574,7 +574,7 @@ JavaScriptCompiler.prototype = {
this.popStack(),
', ',
this.contextName(0),
')'
')',
]);
},
@@ -649,9 +649,9 @@ JavaScriptCompiler.prototype = {
'fn',
'props',
'container',
options
options,
]),
' || fn;'
' || fn;',
]);
},
@@ -685,7 +685,7 @@ JavaScriptCompiler.prototype = {
let functionLookupCode = [
'(',
this.itemsSeparatedBy(possibleFunctionCalls, '||'),
')'
')',
];
let functionCall = this.source.functionCall(
functionLookupCode,
@@ -759,7 +759,7 @@ JavaScriptCompiler.prototype = {
this.aliasable('"function"'),
' ? ',
this.source.functionCall('helper', 'call', helper.callParams),
' : helper))'
' : helper))',
]);
},
@@ -1054,7 +1054,7 @@ JavaScriptCompiler.prototype = {
params: params,
paramsInit: paramsInit,
name: foundHelper,
callParams: [callContext].concat(params)
callParams: [callContext].concat(params),
};
},
@@ -1115,7 +1115,7 @@ JavaScriptCompiler.prototype = {
} else {
return options;
}
}
},
};
(function () {
@@ -1175,7 +1175,7 @@ function strictLookup(requireTerminal, compiler, parts, i, type) {
compiler.quotedString(parts[i]),
', ',
JSON.stringify(compiler.source.currentLocation),
' )'
' )',
];
} else {
return stack;
+5 -2
View File
@@ -1,7 +1,9 @@
import { extend } from '../utils';
export default function (instance) {
instance.registerDecorator('inline', function(fn, props, container, options) {
instance.registerDecorator(
'inline',
function (fn, props, container, options) {
let ret = fn;
if (!props.partials) {
props.partials = {};
@@ -18,5 +20,6 @@ export default function(instance) {
props.partials[options.args[0]] = options.fn;
return ret;
});
}
);
}
+2 -2
View File
@@ -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.
+1 -1
View File
@@ -27,7 +27,7 @@ export default function(instance) {
return instance.helpers['if'].call(this, conditional, {
fn: options.inverse,
inverse: options.fn,
hash: options.hash
hash: options.hash,
});
});
}
+1 -1
View File
@@ -17,7 +17,7 @@ export default function(instance) {
return fn(context, {
data: data,
blockParams: [context]
blockParams: [context],
});
} else {
return options.inverse(this);
+4 -4
View File
@@ -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];
});
}
+1 -1
View File
@@ -33,7 +33,7 @@ let logger = {
}
console[method](...message); // eslint-disable-line no-console
}
}
},
};
export default logger;
+7 -7
View File
@@ -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(
@@ -118,7 +118,7 @@ export function template(templateSpec, env) {
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);
@@ -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);
});
}
+1 -1
View File
@@ -5,7 +5,7 @@ const escape = {
'"': '&quot;',
"'": '&#x27;',
'`': '&#x60;',
'=': '&#x3D;'
'=': '&#x3D;',
};
const badChars = /[&<>"'`=]/g,
+10 -7
View File
@@ -57,7 +57,7 @@ function loadStrings(opts, callback) {
strings = strings.map((string, index) => ({
name: names[index],
path: names[index],
source: string
source: string,
}));
callback(err, strings);
}
@@ -75,7 +75,10 @@ function loadFiles(opts, callback) {
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) {
@@ -132,7 +135,7 @@ function loadFiles(opts, callback) {
ret.push({
path: path,
name: name,
source: data
source: data,
});
callback();
@@ -222,7 +225,7 @@ module.exports.cli = function(opts) {
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,
},
});
}
+1 -1
View File
@@ -5,5 +5,5 @@ module.exports = {
functions: 100,
statements: 100,
exclude: ['**/spec/**'],
reporter: 'html'
reporter: 'html',
};
+11 -8
View File
@@ -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": {
+1 -1
View File
@@ -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",
+1 -1
View File
@@ -1,5 +1,5 @@
module.exports = {
tabWidth: 2,
semi: true,
singleQuote: true
singleQuote: true,
};
+4 -4
View File
@@ -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',
},
};
+6 -6
View File
@@ -24,7 +24,7 @@ describe('ast', function() {
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,7 +40,7 @@ describe('ast', function() {
AST.helpers.helperExpression({
type: 'MustacheStatement',
params: [],
hash: {}
hash: {},
}),
true
);
@@ -50,7 +50,7 @@ describe('ast', function() {
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,7 +66,7 @@ describe('ast', function() {
AST.helpers.helperExpression({
type: 'BlockStatement',
params: [],
hash: {}
hash: {},
}),
true
);
+43 -65
View File
@@ -6,9 +6,7 @@ beforeEach(function() {
describe('basic context', function () {
it('most basic', function () {
expectTemplate('{{foo}}')
.withInput({ foo: 'foo' })
.toCompileTo('foo');
expectTemplate('{{foo}}').withInput({ foo: 'foo' }).toCompileTo('foo');
});
it('escaping', function () {
@@ -37,16 +35,14 @@ describe('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');
expectTemplate('{{.}}{{length}}').withInput('bye').toCompileTo('bye3');
});
it('compiling with an undefined context', function () {
@@ -63,7 +59,7 @@ describe('basic context', function() {
expectTemplate('{{! Goodbye}}Goodbye\n{{cruel}}\n{{world}}!')
.withInput({
cruel: 'cruel',
world: 'world'
world: 'world',
})
.withMessage('comments are ignored')
.toCompileTo('Goodbye\ncruel\nworld!');
@@ -92,7 +88,7 @@ describe('basic context', function() {
expectTemplate(string)
.withInput({
goodbye: true,
world: 'world'
world: 'world',
})
.withMessage('booleans show the contents when true')
.toCompileTo('GOODBYE cruel world!');
@@ -100,7 +96,7 @@ 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!');
@@ -110,13 +106,11 @@ describe('basic context', 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 } })
@@ -128,13 +122,11 @@ 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');
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');
@@ -164,7 +156,7 @@ describe('basic context', function() {
' ' +
typeof options
);
}
},
})
.toCompileTo('true true object');
@@ -172,7 +164,7 @@ describe('basic context', function() {
.withInput({
undefined: function () {
return 'undefined!';
}
},
})
.toCompileTo('undefined!');
@@ -180,7 +172,7 @@ describe('basic context', function() {
.withInput({
null: function () {
return 'null!';
}
},
})
.toCompileTo('null!');
});
@@ -243,7 +235,7 @@ describe('basic context', function() {
.withInput({
awesome: function () {
return new Handlebars.SafeString("&'\\<>");
}
},
})
.withMessage("functions returning safestrings aren't escaped")
.toCompileTo("&'\\<>");
@@ -254,7 +246,7 @@ describe('basic context', function() {
.withInput({
awesome: function () {
return 'Awesome';
}
},
})
.withMessage('functions are called and render their output')
.toCompileTo('Awesome');
@@ -264,7 +256,7 @@ describe('basic context', function() {
awesome: function () {
return this.more;
},
more: 'More awesome'
more: 'More awesome',
})
.withMessage('functions are bound to the context')
.toCompileTo('More awesome');
@@ -276,7 +268,7 @@ describe('basic context', function() {
awesome: function (context) {
return context;
},
frank: 'Frank'
frank: 'Frank',
})
.withMessage('functions are called with context arguments')
.toCompileTo('Frank');
@@ -288,9 +280,9 @@ describe('basic context', function() {
bar: {
awesome: function (context) {
return context;
}
},
frank: 'Frank'
},
frank: 'Frank',
})
.withMessage('functions are called with context arguments')
.toCompileTo('Frank');
@@ -302,7 +294,7 @@ describe('basic context', function() {
awesome: function (context) {
return context;
},
frank: 'Frank'
frank: 'Frank',
})
.withMessage('functions are called with context arguments')
.toCompileTo('Frank');
@@ -313,7 +305,7 @@ describe('basic context', function() {
.withInput({
awesome: function (context, options) {
return options.fn(context);
}
},
})
.withMessage('block functions are called with context and options')
.toCompileTo('inner 1');
@@ -327,7 +319,7 @@ describe('basic context', function() {
value: true,
awesome: function (context, options) {
return options.fn(context);
}
},
})
.withMessage('block functions are called with context and options')
.toCompileTo('inner 1');
@@ -338,7 +330,7 @@ describe('basic context', function() {
.withInput({
awesome: function (options) {
return options.fn(this);
}
},
})
.withMessage('block functions are called with options')
.toCompileTo('inner');
@@ -350,8 +342,8 @@ describe('basic context', function() {
foo: {
awesome: function () {
return this;
}
}
},
},
})
.withMessage('block functions are called with options')
.toCompileTo('inner');
@@ -365,7 +357,7 @@ describe('basic context', function() {
value: true,
awesome: function () {
return this;
}
},
})
.withMessage('block functions are called with options')
.toCompileTo('inner');
@@ -452,9 +444,7 @@ describe('basic context', function() {
.withInput({ person: { name: null } })
.toCompileTo('');
expectTemplate('{{person/name}}')
.withInput({ person: {} })
.toCompileTo('');
expectTemplate('{{person/name}}').withInput({ person: {} }).toCompileTo('');
});
it('this keyword in paths', function () {
@@ -465,7 +455,7 @@ 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');
@@ -477,9 +467,7 @@ describe('basic context', function() {
'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' } })
@@ -490,7 +478,7 @@ describe('basic context', function() {
var helpers = {
foo: function (value) {
return 'bar ' + value;
}
},
};
expectTemplate('{{#goodbyes}}{{foo this}}{{/goodbyes}}')
@@ -501,7 +489,7 @@ 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')
@@ -519,7 +507,7 @@ describe('basic context', function() {
foo: function (value) {
return value;
},
this: 'bar'
this: 'bar',
})
.toCompileTo('bar');
@@ -528,7 +516,7 @@ describe('basic context', function() {
foo: function (value) {
return value;
},
text: { this: 'bar' }
text: { this: 'bar' },
})
.toCompileTo('bar');
});
@@ -536,13 +524,11 @@ describe('basic context', 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');
});
@@ -550,21 +536,17 @@ describe('basic context', 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');
});
@@ -572,13 +554,9 @@ describe('basic context', 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 () {
@@ -586,7 +564,7 @@ describe('basic context', function() {
.withInput({
false: function () {
return 'bar';
}
},
})
.withHelper('foo', function (arg) {
return arg;
+24 -24
View File
@@ -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,7 +17,7 @@ describe('blocks', function() {
expectTemplate(string)
.withInput({
goodbyes: [],
world: 'world'
world: 'world',
})
.withMessage('Arrays ignore the contents when empty')
.toCompileTo('cruel world!');
@@ -31,9 +31,9 @@ describe('blocks', function() {
goodbyes: [
{ text: 'goodbye' },
{ text: 'Goodbye' },
{ text: 'GOODBYE' }
{ text: 'GOODBYE' },
],
world: 'world'
world: 'world',
})
.withCompileOptions({ compat: false })
.toCompileTo('goodbyeGoodbyeGOODBYE goodbyeGoodbyeGOODBYE');
@@ -47,9 +47,9 @@ 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!');
@@ -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,7 +73,7 @@ describe('blocks', function() {
expectTemplate(string)
.withInput({
goodbyes: [],
world: 'world'
world: 'world',
})
.withMessage('Arrays ignore the contents when empty')
.toCompileTo('cruel world!');
@@ -86,8 +86,8 @@ describe('blocks', function() {
goodbyes: [
{ text: 'goodbye' },
{ text: 'Goodbye' },
{ text: 'GOODBYE' }
]
{ text: 'GOODBYE' },
],
})
.withMessage(
'Templates can access variables in contexts up the stack with relative path syntax'
@@ -104,8 +104,8 @@ describe('blocks', function() {
goodbyes: [
{ text: 'goodbye' },
{ text: 'Goodbye' },
{ text: 'GOODBYE' }
]
{ text: 'GOODBYE' },
],
})
.toCompileTo('AlanAlanAlanAlanAlanAlan');
});
@@ -122,7 +122,7 @@ describe('blocks', function() {
)
.withInput({
omg: 'OMG!',
outer: [{ sibling: 'sad', inner: [{ text: 'goodbye' }] }]
outer: [{ sibling: 'sad', inner: [{ text: 'goodbye' }] }],
})
.toCompileTo('Goodbye cruel sad OMG!');
});
@@ -135,8 +135,8 @@ describe('blocks', function() {
.withInput({
person: [
{ first: 'Alan', last: 'Johnson' },
{ first: 'Alan', last: 'Johnson' }
]
{ first: 'Alan', last: 'Johnson' },
],
})
.toCompileTo('Alan JohnsonAlan Johnson');
});
@@ -202,7 +202,7 @@ describe('blocks', function() {
expectTemplate('{{#people}}{{name}}{{^}}{{none}}{{/people}}')
.withInput({
none: 'No people',
people: []
people: [],
})
.toCompileTo('No people');
});
@@ -252,7 +252,7 @@ describe('blocks', 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.');
});
@@ -274,7 +274,7 @@ describe('blocks', function() {
)
.withInput({
omg: { yes: 'OMG!' },
outer: [{ inner: [{ yes: 'no', text: 'goodbye' }] }]
outer: [{ inner: [{ yes: 'no', text: 'goodbye' }] }],
})
.withCompileOptions({ compat: true })
.toCompileTo('Goodbye cruel OMG!');
@@ -286,7 +286,7 @@ describe('blocks', function() {
)
.withInput({
omg: { no: 'OMG!' },
outer: [{ inner: [{ yes: 'no', text: 'goodbye' }] }]
outer: [{ inner: [{ yes: 'no', text: 'goodbye' }] }],
})
.withCompileOptions({ compat: true })
.toCompileTo('Goodbye cruel ');
@@ -345,7 +345,7 @@ describe('blocks', function() {
},
nested: function (fn, props, container, options) {
props.nested = options.fn();
}
},
})
.toCompileTo('success');
});
@@ -421,7 +421,7 @@ describe('blocks', function() {
handlebarsEnv.registerDecorator({
foo: function () {},
bar: function() {}
bar: function () {},
});
equals(!!handlebarsEnv.decorators.foo, true);
@@ -442,7 +442,7 @@ describe('blocks', function() {
},
testHelper: function () {
return 'found it!';
}
},
},
{}
);
+57 -55
View File
@@ -6,7 +6,7 @@ describe('builtin helpers', function() {
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,7 +63,7 @@ describe('builtin helpers', function() {
)
.withInput({
goodbye: 0,
world: 'world'
world: 'world',
})
.withMessage('if with zero does not show the contents')
.toCompileTo('GOODBYE cruel world!');
@@ -77,7 +77,7 @@ describe('builtin helpers', function() {
goodbye: function () {
return true;
},
world: 'world'
world: 'world',
})
.withMessage(
'if with function shows the contents when function returns true'
@@ -89,7 +89,7 @@ describe('builtin helpers', function() {
goodbye: function () {
return this.world;
},
world: 'world'
world: 'world',
})
.withMessage(
'if with function shows the contents when function returns string'
@@ -101,7 +101,7 @@ describe('builtin helpers', function() {
goodbye: function () {
return false;
},
world: 'world'
world: 'world',
})
.withMessage(
'if with function does not show the contents when returns false'
@@ -113,7 +113,7 @@ describe('builtin helpers', function() {
goodbye: function () {
return this.foo;
},
world: 'world'
world: 'world',
})
.withMessage(
'if with function does not show the contents when returns undefined'
@@ -127,7 +127,7 @@ describe('builtin helpers', function() {
)
.withInput({
foo: { goodbye: true },
world: 'world'
world: 'world',
})
.toCompileTo('GOODBYE cruel world!');
});
@@ -139,8 +139,8 @@ describe('builtin helpers', function() {
.withInput({
person: {
first: 'Alan',
last: 'Johnson'
}
last: 'Johnson',
},
})
.toCompileTo('Alan Johnson');
});
@@ -151,9 +151,9 @@ describe('builtin helpers', function() {
person: function () {
return {
first: 'Alan',
last: 'Johnson'
last: 'Johnson',
};
}
},
})
.toCompileTo('Alan Johnson');
});
@@ -169,8 +169,8 @@ describe('builtin helpers', function() {
.withInput({
person: {
first: 'Alan',
last: 'Johnson'
}
last: 'Johnson',
},
})
.toCompileTo('Alan Johnson');
});
@@ -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,7 +210,7 @@ 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!');
@@ -222,9 +222,9 @@ describe('builtin helpers', function() {
goodbyes: [
{ text: 'goodbye' },
{ text: 'Goodbye' },
{ text: 'GOODBYE' }
{ text: 'GOODBYE' },
],
world: 'world'
world: 'world',
})
.withRuntimeOptions({ data: false })
.withCompileOptions({ data: false })
@@ -272,7 +272,7 @@ describe('builtin helpers', function() {
expectTemplate(string)
.withInput({
goodbyes: {},
world: 'world'
world: 'world',
})
.toCompileTo('cruel world!');
});
@@ -285,9 +285,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('0. goodbye! 1. Goodbye! 2. GOODBYE! 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(
@@ -317,7 +317,7 @@ describe('builtin helpers', function() {
)
.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!'
@@ -341,9 +341,9 @@ 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!');
@@ -357,9 +357,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('goodbye! 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(
@@ -389,7 +389,7 @@ describe('builtin helpers', function() {
)
.withInput({
goodbyes: { foo: { text: 'goodbye' }, bar: { text: 'Goodbye' } },
world: 'world'
world: 'world',
})
.withMessage('The @first variable is used')
.toCompileTo('goodbye! cruel world!');
@@ -403,9 +403,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('GOODBYE! cruel world!');
@@ -417,7 +417,7 @@ describe('builtin helpers', function() {
)
.withInput({
goodbyes: { foo: { text: 'goodbye' }, bar: { text: 'Goodbye' } },
world: 'world'
world: 'world',
})
.withMessage('The @last variable is used')
.toCompileTo('Goodbye! 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(
@@ -450,10 +450,10 @@ describe('builtin helpers', 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'
@@ -479,9 +479,9 @@ 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!');
@@ -495,8 +495,8 @@ describe('builtin helpers', function() {
.withMessage('should output data')
.withRuntimeOptions({
data: {
exclaim: '!'
}
exclaim: '!',
},
})
.toCompileTo('a!b!c!');
});
@@ -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'
@@ -705,7 +705,11 @@ describe('builtin helpers', function() {
it('should handle hash log levels', function () {
var called = false;
console.info = console.log = console.error = console.debug = function() {
console.info =
console.log =
console.error =
console.debug =
function () {
called = true;
console.info = console.log = console.error = console.debug = $log;
};
@@ -742,9 +746,7 @@ describe('builtin helpers', function() {
console.log = $log;
};
expectTemplate('{{log}}')
.withInput({ blah: 'whee' })
.toCompileTo('');
expectTemplate('{{log}}').withInput({ blah: 'whee' }).toCompileTo('');
expect(called).to.be.true();
});
/* eslint-enable no-console */
+2 -2
View File
@@ -122,7 +122,7 @@ describe('compiler', function() {
equal(
Handlebars.compile({
type: 'Program',
body: [{ type: 'ContentStatement', value: 'Hello' }]
body: [{ type: 'ContentStatement', value: 'Hello' }],
})(),
'Hello'
);
@@ -191,7 +191,7 @@ describe('compiler', function() {
/return "Hello"/.test(
Handlebars.precompile({
type: 'Program',
body: [{ type: 'ContentStatement', value: 'Hello' }]
body: [{ type: 'ContentStatement', value: 'Hello' }],
})
),
true
+7 -7
View File
@@ -93,8 +93,8 @@ describe('data', function() {
data: {
hello: function () {
return 'hello';
}
}
},
},
})
.toCompileTo('hello');
});
@@ -105,8 +105,8 @@ describe('data', function() {
data: {
hello: function (arg) {
return arg;
}
}
},
},
})
.toCompileTo('hello');
});
@@ -159,7 +159,7 @@ describe('data', 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) {
return options.fn(this);
@@ -269,8 +269,8 @@ describe('data', function() {
})
.withRuntimeOptions({
data: {
depth: 0
}
depth: 0,
},
})
.toCompileTo('2 1 0');
});
+1 -1
View File
@@ -32,7 +32,7 @@ global.CompilerContext = {
},
compileWithPartial: function (template, options) {
return handlebarsEnv.compile(template, options);
}
},
};
function safeEval(templateSpec) {
+1 -1
View File
@@ -17,7 +17,7 @@ global.CompilerContext = {
},
compileWithPartial: function (template, options) {
return handlebarsEnv.compile(template, options);
}
},
};
function safeEval(templateSpec) {
+5 -2
View File
@@ -31,7 +31,10 @@ global.CompilerContext = {
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,
@@ -55,7 +58,7 @@ global.CompilerContext = {
handlebarsEnv.JavaScriptCompiler = JavaScriptCompiler;
return handlebarsEnv.compile(template, options);
}
},
};
function safeEval(templateSpec) {
+36 -36
View File
@@ -3,7 +3,7 @@ describe('helpers', function() {
expectTemplate('{{#goodbyes}}{{{link ../prefix}}}{{/goodbyes}}')
.withInput({
prefix: '/root',
goodbyes: [{ text: 'Goodbye', url: 'goodbye' }]
goodbyes: [{ text: 'Goodbye', url: 'goodbye' }],
})
.withHelper('link', function (prefix) {
return (
@@ -111,7 +111,7 @@ describe('helpers', function() {
)
.withInput({
prefix: '/root',
goodbyes: [{ text: 'Goodbye', url: 'goodbye' }]
goodbyes: [{ text: 'Goodbye', url: 'goodbye' }],
})
.withHelper('link', function (prefix, options) {
return (
@@ -133,7 +133,7 @@ describe('helpers', function() {
)
.withInput({
prefix: '/root',
goodbyes: [{ text: 'Goodbye', url: 'goodbye' }]
goodbyes: [{ text: 'Goodbye', url: 'goodbye' }],
})
.withHelper('link', function (prefix, options) {
return (
@@ -152,13 +152,13 @@ describe('helpers', function() {
it('helper returning undefined value', function () {
expectTemplate(' {{nothere}}')
.withHelpers({
nothere: function() {}
nothere: function () {},
})
.toCompileTo(' ');
expectTemplate(' {{#nothere}}{{/nothere}}')
.withHelpers({
nothere: function() {}
nothere: function () {},
})
.toCompileTo(' ');
});
@@ -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(
@@ -232,7 +232,7 @@ describe('helpers', function() {
'{{#form yehuda}}<p>{{name}}</p>{{#link}}Hello{{/link}}{{/form}}'
)
.withInput({
yehuda: { name: 'Yehuda' }
yehuda: { name: 'Yehuda' },
})
.withHelper('link', function (options) {
return '<a href="' + this.name + '">' + options.fn(this) + '</a>';
@@ -278,7 +278,7 @@ 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')
@@ -289,13 +289,13 @@ describe('helpers', function() {
var hash = {
helper: function () {
return 'winning';
}
},
};
hash.hash = hash;
var helpers = {
'./helper': function () {
return 'fail';
}
},
};
expectTemplate('{{./helper 1}}')
@@ -316,7 +316,7 @@ describe('helpers', function() {
.withHelpers({
world: function () {
return 'world';
}
},
})
.withMessage('helpers hash is available')
.toCompileTo('Goodbye cruel world!');
@@ -326,7 +326,7 @@ describe('helpers', function() {
.withHelpers({
world: function () {
return 'world';
}
},
})
.withMessage('helpers hash is available inside other blocks')
.toCompileTo('Goodbye cruel world!');
@@ -338,7 +338,7 @@ describe('helpers', function() {
.withHelpers({
lookup: function () {
return 'helpers';
}
},
})
.withMessage('helpers hash has precedence escaped expansion')
.toCompileTo('helpers');
@@ -348,7 +348,7 @@ describe('helpers', function() {
.withHelpers({
lookup: function () {
return 'helpers';
}
},
})
.withMessage('helpers hash has precedence simple expansion')
.toCompileTo('helpers');
@@ -360,7 +360,7 @@ describe('helpers', function() {
.withHelpers({
helper: function () {
return 'helper';
}
},
})
.withMessage('helpers hash is available in nested contexts.')
.toCompileTo('helper');
@@ -378,7 +378,7 @@ describe('helpers', function() {
.withHelpers({
world: function () {
return 'world!';
}
},
})
.toCompileTo('found it! Goodbye cruel world!!');
});
@@ -406,7 +406,7 @@ describe('helpers', function() {
},
testHelper: function () {
return 'found it!';
}
},
});
expectTemplate(
@@ -426,7 +426,7 @@ describe('helpers', function() {
},
testHelper: function () {
return 'found it!';
}
},
},
{}
);
@@ -675,7 +675,7 @@ describe('helpers', function() {
it('Known helper should render helper', function () {
expectTemplate('{{hello}}')
.withCompileOptions({
knownHelpers: { hello: true }
knownHelpers: { hello: true },
})
.withHelper('hello', function () {
return 'foo';
@@ -687,7 +687,7 @@ describe('helpers', function() {
expectTemplate('{{typeof hello}}')
.withCompileOptions({
knownHelpers: { typeof: true },
knownHelpersOnly: true
knownHelpersOnly: true,
})
.withHelper('typeof', function (arg) {
return typeof arg;
@@ -701,7 +701,7 @@ describe('helpers', function() {
it('Builtin helpers available in knownHelpers only mode', function () {
expectTemplate('{{#unless foo}}bar{{/unless}}')
.withCompileOptions({
knownHelpersOnly: true
knownHelpersOnly: true,
})
.toCompileTo('bar');
});
@@ -709,7 +709,7 @@ describe('helpers', function() {
it('Field lookup works in knownHelpers only mode', function () {
expectTemplate('{{foo}}')
.withCompileOptions({
knownHelpersOnly: true
knownHelpersOnly: true,
})
.withInput({ foo: 'bar' })
.toCompileTo('bar');
@@ -718,7 +718,7 @@ describe('helpers', function() {
it('Conditional blocks work in knownHelpers only mode', function () {
expectTemplate('{{#foo}}bar{{/foo}}')
.withCompileOptions({
knownHelpersOnly: true
knownHelpersOnly: true,
})
.withInput({ foo: 'baz' })
.toCompileTo('bar');
@@ -727,7 +727,7 @@ describe('helpers', function() {
it('Invert blocks work in knownHelpers only mode', function () {
expectTemplate('{{^foo}}bar{{/foo}}')
.withCompileOptions({
knownHelpersOnly: true
knownHelpersOnly: true,
})
.withInput({ foo: false })
.toCompileTo('bar');
@@ -736,13 +736,13 @@ describe('helpers', function() {
it('Functions are bound to the context in knownHelpers only mode', function () {
expectTemplate('{{foo}}')
.withCompileOptions({
knownHelpersOnly: true
knownHelpersOnly: true,
})
.withInput({
foo: function () {
return this.bar;
},
bar: 'bar'
bar: 'bar',
})
.toCompileTo('bar');
});
@@ -760,7 +760,7 @@ describe('helpers', function() {
.withInput({
truthy: function () {
return true;
}
},
})
.toCompileTo('yep');
});
@@ -773,7 +773,7 @@ describe('helpers', function() {
},
truthiness: function () {
return false;
}
},
})
.toCompileTo('');
});
@@ -789,7 +789,7 @@ describe('helpers', function() {
},
helper: function () {
return 'ran: ' + arguments[arguments.length - 1].name;
}
},
};
it('should include in ambiguous mustache calls', function () {
@@ -826,7 +826,7 @@ describe('helpers', function() {
expectTemplate('{{helper}}')
.withCompileOptions({
knownHelpers: { helper: true },
knownHelpersOnly: true
knownHelpersOnly: true,
})
.withHelpers(helpers)
.toCompileTo('ran: helper');
@@ -858,7 +858,7 @@ describe('helpers', function() {
})
.withInput({
goodbye: 'goodbye',
world: 'world'
world: 'world',
})
.withMessage('Helper executed')
.toCompileTo('GOODBYE cruel WORLD');
@@ -874,7 +874,7 @@ describe('helpers', function() {
})
.withInput({
goodbye: 'goodbye',
world: 'world'
world: 'world',
})
.withMessage('Helper executed')
.toCompileTo('GOODBYE cruel WORLD');
@@ -890,7 +890,7 @@ describe('helpers', function() {
})
.withInput({
goodbye: 'goodbye',
world: 'world'
world: 'world',
})
.withMessage('Helper not executed')
.toCompileTo('goodbye cruel WORLD cruel GOODBYE');
@@ -908,7 +908,7 @@ describe('helpers', function() {
})
.withInput({
goodbye: 'goodbye',
world: 'world'
world: 'world',
})
.withMessage('Helper executed')
.toCompileTo('GOODBYE cruel WORLD goodbye');
@@ -964,7 +964,7 @@ describe('helpers', function() {
{ value: 'bar' },
{
blockParams:
options.fn.blockParams === 1 ? [value++, value++] : undefined
options.fn.blockParams === 1 ? [value++, value++] : undefined,
}
);
})
+4 -2
View File
@@ -69,11 +69,13 @@ describe('javascript-compiler api', 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() {
handlebarsEnv.JavaScriptCompiler.prototype.initializeBuffer =
function () {
return this.quotedString('foo_');
};
expectTemplate('{{foo}} ')
+49 -52
View File
@@ -5,8 +5,8 @@ describe('partials', function() {
var hash = {
dudes: [
{ name: 'Yehuda', url: 'http://yehuda' },
{ name: 'Alan', url: 'http://alan' }
]
{ name: 'Alan', url: 'http://alan' },
],
};
expectTemplate(string)
@@ -28,13 +28,13 @@ describe('partials', function() {
var hash = {
dudes: [
{ name: 'Yehuda', url: 'http://yehuda' },
{ name: 'Alan', url: 'http://alan' }
]
{ name: 'Alan', url: 'http://alan' },
],
};
var helpers = {
partial: function () {
return 'dude';
}
},
};
expectTemplate(string)
@@ -57,8 +57,8 @@ describe('partials', function() {
.withInput({
dudes: [
{ name: 'Yehuda', url: 'http://yehuda' },
{ name: 'Alan', url: 'http://alan' }
]
{ name: 'Alan', url: 'http://alan' },
],
})
.withHelper('partial', function () {
return 'missing';
@@ -72,8 +72,8 @@ describe('partials', function() {
.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')
@@ -85,8 +85,8 @@ describe('partials', function() {
var hash = {
dudes: [
{ name: 'Yehuda', url: 'http://yehuda' },
{ name: 'Alan', url: 'http://alan' }
]
{ name: 'Alan', url: 'http://alan' },
],
};
expectTemplate('Dudes: {{#dudes}}{{>dude}}{{/dudes}}')
@@ -127,8 +127,8 @@ describe('partials', function() {
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.')
@@ -140,12 +140,12 @@ describe('partials', function() {
.withInput({
dudes: [
{ name: 'Yehuda', url: 'http://yehuda' },
{ name: 'Alan', url: 'http://alan' }
]
{ name: 'Alan', url: 'http://alan' },
],
})
.withPartials({
dude: '{{name}} {{> url}} ',
url: '<a href="{{url}}">{{url}}</a>'
url: '<a href="{{url}}">{{url}}</a>',
})
.withMessage('Partials are rendered inside of other partials')
.toCompileTo(
@@ -186,8 +186,8 @@ 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.')
@@ -234,7 +234,7 @@ describe('partials', function() {
it('Multiple partial registration', function () {
handlebarsEnv.registerPartial({
'shared/dude': '{{name}}',
globalTest: '{{anotherDude}}'
globalTest: '{{anotherDude}}',
});
expectTemplate('Dudes: {{> shared/dude}} {{> globalTest}}')
@@ -281,8 +281,8 @@ describe('partials', function() {
.withInput({
dudes: [
{ name: 'Yehuda', url: 'http://yehuda' },
{ name: 'Alan', url: 'http://alan' }
]
{ name: 'Alan', url: 'http://alan' },
],
})
.withPartial('dude', '')
.toCompileTo('Dudes: ');
@@ -341,7 +341,7 @@ describe('partials', function() {
expectTemplate('{{#> dude}}{{value}}{{/dude}}')
.withInput({ context: { value: 'success' } })
.withPartials({
dude: '{{#with context}}{{> @partial-block }}{{/with}}'
dude: '{{#with context}}{{> @partial-block }}{{/with}}',
})
.toCompileTo('success');
});
@@ -350,8 +350,7 @@ describe('partials', function() {
expectTemplate('{{#> dude}}in-block: {{@root/value}}{{/dude}}')
.withInput({ value: 'success' })
.withPartials({
dude:
'<code>before-block: {{@root/value}} {{> @partial-block }}</code>'
dude: '<code>before-block: {{@root/value}} {{> @partial-block }}</code>',
})
.toCompileTo('<code>before-block: success in-block: success</code>');
});
@@ -361,11 +360,10 @@ describe('partials', function() {
'<template>{{#> list value}}value = {{.}}{{/list}}</template>'
)
.withInput({
value: ['a', 'b', 'c']
value: ['a', 'b', 'c'],
})
.withPartials({
list:
'<list>{{#each .}}<item>{{> @partial-block}}</item>{{/each}}</list>'
list: '<list>{{#each .}}<item>{{> @partial-block}}</item>{{/each}}</list>',
})
.toCompileTo(
'<template><list><item>value = a</item><item>value = b</item><item>value = c</item></list></template>'
@@ -376,8 +374,7 @@ describe('partials', function() {
expectTemplate('{{#> dude}}{{value}}{{/dude}}')
.withInput({ context: { value: 'success' } })
.withPartials({
dude:
'{{#with context}}{{> @partial-block }} {{> @partial-block }}{{/with}}'
dude: '{{#with context}}{{> @partial-block }} {{> @partial-block }}{{/with}}',
})
.toCompileTo('success success');
});
@@ -386,7 +383,7 @@ describe('partials', function() {
expectTemplate('{{#> dude}}{{../context/value}}{{/dude}}')
.withInput({ context: { value: 'success' } })
.withPartials({
dude: '{{#with context}}{{> @partial-block }}{{/with}}'
dude: '{{#with context}}{{> @partial-block }}{{/with}}',
})
.toCompileTo('success');
});
@@ -406,7 +403,7 @@ describe('partials', function() {
.withPartials({
outer:
'<outer>{{#> nested}}<outer-block>{{> @partial-block}}</outer-block>{{/nested}}</outer>',
nested: '<nested>{{> @partial-block}}</nested>'
nested: '<nested>{{> @partial-block}}</nested>',
})
.toCompileTo(
'<template><outer><nested><outer-block>success</outer-block></nested></outer></template>'
@@ -419,7 +416,7 @@ describe('partials', function() {
.withPartials({
outer:
'<outer>{{#> nested}}<outer-block>{{> @partial-block}}</outer-block>{{/nested}}{{> @partial-block}}</outer>',
nested: '<nested>{{> @partial-block}}</nested>'
nested: '<nested>{{> @partial-block}}</nested>',
})
.toCompileTo(
'<template><outer><nested><outer-block>success</outer-block></nested>success</outer></template>'
@@ -432,7 +429,7 @@ describe('partials', function() {
.withPartials({
outer:
'<outer>{{#> nested}}<outer-block>{{> @partial-block}} {{> @partial-block}}</outer-block>{{/nested}}{{> @partial-block}}+{{> @partial-block}}</outer>',
nested: '<nested>{{> @partial-block}}</nested>'
nested: '<nested>{{> @partial-block}}</nested>',
})
.toCompileTo(
'<template><outer><nested><outer-block>success success</outer-block></nested>success+success</outer></template>'
@@ -445,7 +442,7 @@ describe('partials', function() {
.withPartials({
outer:
'<outer>{{#> nested}}<outer-block>{{> @partial-block}} {{> @partial-block}}</outer-block>{{/nested}}</outer>',
nested: '<nested>{{> @partial-block}}{{> @partial-block}}</nested>'
nested: '<nested>{{> @partial-block}}{{> @partial-block}}</nested>',
})
.toCompileTo(
'<template><outer>' +
@@ -485,7 +482,7 @@ describe('partials', function() {
.withPartials({
myPartial: function () {
return 'fail';
}
},
})
.toCompileTo('success');
});
@@ -566,8 +563,8 @@ describe('partials', function() {
.withInput({
dudes: [
{ name: 'Yehuda', url: 'http://yehuda' },
{ name: 'Alan', url: 'http://alan' }
]
{ name: 'Alan', url: 'http://alan' },
],
})
.withPartial('dude', '{{name}}\n')
.toCompileTo('Dudes:\n Yehuda\n Alan\n');
@@ -578,12 +575,12 @@ describe('partials', function() {
.withInput({
dudes: [
{ name: 'Yehuda', url: 'http://yehuda' },
{ name: 'Alan', url: 'http://alan' }
]
{ name: 'Alan', url: 'http://alan' },
],
})
.withPartials({
dude: '{{name}}\n {{> url}}',
url: '{{url}}!\n'
url: '{{url}}!\n',
})
.toCompileTo(
'Dudes:\n Yehuda\n http://yehuda!\n Alan\n http://alan!\n'
@@ -595,12 +592,12 @@ describe('partials', function() {
.withInput({
dudes: [
{ name: 'Yehuda', url: 'http://yehuda' },
{ name: 'Alan', url: 'http://alan' }
]
{ name: 'Alan', url: 'http://alan' },
],
})
.withPartials({
dude: '{{name}}\n {{> url}}',
url: '{{url}}!\n'
url: '{{url}}!\n',
})
.withCompileOptions({ preventIndent: true })
.toCompileTo(
@@ -616,8 +613,8 @@ describe('partials', function() {
root: 'yes',
dudes: [
{ name: 'Yehuda', url: 'http://yehuda' },
{ name: 'Alan', url: 'http://alan' }
]
{ name: 'Alan', url: 'http://alan' },
],
})
.withPartials({ dude: '{{name}} ({{url}}) {{root}} ' })
.withCompileOptions({ compat: true })
@@ -632,8 +629,8 @@ describe('partials', function() {
root: 'yes',
dudes: [
{ name: 'Yehuda', url: 'http://yehuda' },
{ name: 'Alan', url: 'http://alan' }
]
{ name: 'Alan', url: 'http://alan' },
],
})
.withPartials({ dude: '{{name}} ({{url}}) {{root}} ' })
.withCompileOptions({ compat: true })
@@ -648,8 +645,8 @@ describe('partials', function() {
root: 'yes',
dudes: [
{ name: 'Yehuda', url: 'http://yehuda' },
{ name: 'Alan', url: 'http://alan' }
]
{ name: 'Alan', url: 'http://alan' },
],
})
.withPartials({ dude: '{{name}} ({{url}}) {{root}} ' })
.withRuntimeOptions({ data: false })
@@ -665,11 +662,11 @@ describe('partials', function() {
root: 'yes',
dudes: [
{ name: 'Yehuda', url: 'http://yehuda' },
{ name: 'Alan', url: 'http://alan' }
]
{ name: 'Alan', url: 'http://alan' },
],
})
.withPartials({
dude: '{{#dudes}}{{name}} ({{url}}) {{root}} {{/dudes}}'
dude: '{{#dudes}}{{name}} ({{url}}) {{root}} {{/dudes}}',
})
.withCompileOptions({ compat: true })
.toCompileTo(
+9 -9
View File
@@ -19,7 +19,7 @@ describe('precompiler', function() {
emptyTemplate = {
path: __dirname + '/artifacts/empty.handlebars',
name: 'empty',
source: ''
source: '',
},
file,
content,
@@ -115,9 +115,9 @@ describe('precompiler', function() {
Precompiler.cli({
templates: [
__dirname + '/artifacts/empty.handlebars',
__dirname + '/artifacts/empty.handlebars'
__dirname + '/artifacts/empty.handlebars',
],
simple: true
simple: true,
});
},
Handlebars.Exception,
@@ -171,7 +171,7 @@ describe('precompiler', function() {
Precompiler.cli({
templates: [emptyTemplate, emptyTemplate],
amd: true,
namespace: 'foo'
namespace: 'foo',
});
equal(/templates = foo = foo \|\|/.test(log), true);
equal(/return templates/.test(log), true);
@@ -192,7 +192,7 @@ describe('precompiler', function() {
Precompiler.cli({
templates: [emptyTemplate, emptyTemplate],
amd: true,
partial: true
partial: true,
});
equal(/return Handlebars\.partials\[/.test(log), false);
equal(/template\(amd\)/.test(log), true);
@@ -229,7 +229,7 @@ describe('precompiler', function() {
Precompiler.cli({
templates: [emptyTemplate],
simple: true,
output: 'file!'
output: 'file!',
});
equal(file, 'file!');
equal(content, 'simple\n');
@@ -289,7 +289,7 @@ describe('precompiler', function() {
Precompiler.cli({
templates: [emptyTemplate],
min: true,
map: 'foo.js.map'
map: 'foo.js.map',
});
equal(file, 'foo.js.map');
@@ -339,7 +339,7 @@ describe('precompiler', function() {
var opts = {
files: [__dirname + '/artifacts/bom.handlebars'],
extension: 'handlebars',
bom: true
bom: true,
};
Precompiler.loadTemplates(opts, function (err, opts) {
equal(opts.templates[0].source, 'a');
@@ -351,7 +351,7 @@ describe('precompiler', function() {
var opts = {
files: [__dirname + '/artifacts/empty.handlebars'],
simple: true,
root: 'foo/'
root: 'foo/',
};
Precompiler.loadTemplates(opts, function (err, opts) {
equal(opts.templates[0].name, __dirname + '/artifacts/empty');
+37 -45
View File
@@ -6,13 +6,13 @@ describe('Regressions', function() {
{
title: 'The origin of species',
author: {
name: 'Charles Darwin'
}
name: 'Charles Darwin',
},
},
{
title: 'Lazarillo de Tormes'
}
]
title: 'Lazarillo de Tormes',
},
],
})
.withMessage('Renders without an undefined property error')
.toCompileTo('The origin of speciesCharles DarwinLazarillo de Tormes');
@@ -73,11 +73,11 @@ describe('Regressions', function() {
things: [
{ className: 'one', word: '@fat' },
{ className: 'two', word: '@dhg' },
{ className: 'three', word: '@sayrer' }
{ className: 'three', word: '@sayrer' },
],
hasThings: function () {
return true;
}
},
};
var output =
@@ -89,9 +89,7 @@ describe('Regressions', function() {
'<li class=three>@sayrer</li>\n' +
'</ul>.\n';
expectTemplate(string)
.withInput(data)
.toCompileTo(output);
expectTemplate(string).withInput(data).toCompileTo(output);
});
it('GH-408: Multiple loops fail', function () {
@@ -100,7 +98,7 @@ describe('Regressions', function() {
)
.withInput([
{ name: 'John Doe', location: { city: 'Chicago' } },
{ name: 'Jane Doe', location: { city: 'New York' } }
{ name: 'Jane Doe', location: { city: 'New York' } },
])
.withMessage('It should output multiple times')
.toCompileTo('John DoeJane DoeJohn DoeJane DoeJohn DoeJane Doe');
@@ -118,7 +116,7 @@ describe('Regressions', function() {
},
inverse: function (block) {
return block.inverse('');
}
},
};
expectTemplate(succeedingTemplate)
@@ -131,9 +129,7 @@ describe('Regressions', function() {
});
it('GH-458: Scoped this identifier', function () {
expectTemplate('{{./foo}}')
.withInput({ foo: 'bar' })
.toCompileTo('bar');
expectTemplate('{{./foo}}').withInput({ foo: 'bar' }).toCompileTo('bar');
});
it('GH-375: Unicode line terminators', function () {
@@ -144,9 +140,7 @@ describe('Regressions', function() {
/* eslint-disable no-extend-native */
Object.prototype[0xd834] = true;
expectTemplate('{{foo}}')
.withInput({ foo: 'bar' })
.toCompileTo('bar');
expectTemplate('{{foo}}').withInput({ foo: 'bar' }).toCompileTo('bar');
delete Object.prototype[0xd834];
/* eslint-enable no-extend-native */
@@ -174,7 +168,7 @@ describe('Regressions', function() {
name: 'Chris',
value: 10000,
taxed_value: 10000 - 10000 * 0.4,
in_ca: true
in_ca: true,
})
.withMessage('the hello world mustache example works')
.toCompileTo(
@@ -186,15 +180,13 @@ describe('Regressions', function() {
expectTemplate('{{#foo}} This is {{bar}} ~ {{/foo}}')
.withInput({
foo: 0,
bar: 'OK'
bar: 'OK',
})
.toCompileTo(' This is ~ ');
});
it('GH-820: zero pathed rendering', function () {
expectTemplate('{{foo.bar}}')
.withInput({ foo: 0 })
.toCompileTo('');
expectTemplate('{{foo.bar}}').withInput({ foo: 0 }).toCompileTo('');
});
it('GH-837: undefined values for helpers', function () {
@@ -202,7 +194,7 @@ describe('Regressions', function() {
.withHelpers({
str: function (value) {
return value + '';
}
},
})
.toCompileTo('undefined');
});
@@ -214,7 +206,7 @@ describe('Regressions', function() {
.withInput({
name: 'foo',
data: [1],
notData: [1]
notData: [1],
})
.toCompileTo('foo');
});
@@ -225,8 +217,8 @@ describe('Regressions', function() {
data: {
'': 'foo',
name: 'Chris',
value: 10000
}
value: 10000,
},
})
.toCompileTo('Key: \nKey: name\nKey: value\n');
});
@@ -236,10 +228,10 @@ describe('Regressions', function() {
.withHelpers({
wrap: function (options) {
return new Handlebars.SafeString(options.fn());
}
},
})
.withPartials({
partial: '{{#wrap}}<partial>{{/wrap}}'
partial: '{{#wrap}}<partial>{{/wrap}}',
})
.toCompileTo('<partial>');
});
@@ -267,7 +259,7 @@ describe('Regressions', function() {
}
// And to make IE happy, check for the known string as length is not enumerated.
return this === 'bat' ? 'found' : 'not';
}
},
})
.toCompileTo('notfoundbat');
});
@@ -279,7 +271,7 @@ describe('Regressions', function() {
.withPartials({
doctype: 'doctype{{> content}}',
layout:
'{{#> doctype}}{{#*inline "content"}}layout{{> subcontent}}{{/inline}}{{/doctype}}'
'{{#> doctype}}{{#*inline "content"}}layout{{> subcontent}}{{/inline}}{{/doctype}}',
})
.toCompileTo('doctypelayoutsubcontent');
});
@@ -289,7 +281,7 @@ describe('Regressions', function() {
.withPartials({
doctype: 'doctype{{> content}}',
layout:
'{{#> doctype}}{{#*inline "content"}}layout{{#> subcontent}}subcontent{{/subcontent}}{{/inline}}{{/doctype}}'
'{{#> doctype}}{{#*inline "content"}}layout{{#> subcontent}}subcontent{{/subcontent}}{{/inline}}{{/doctype}}',
})
.toCompileTo('doctypelayoutsubcontent');
});
@@ -298,7 +290,7 @@ describe('Regressions', function() {
expectTemplate('{{#> layout}}Outer{{/layout}}')
.withPartials({
layout: '{{#> inner}}Inner{{/inner}}{{> @partial-block }}',
inner: ''
inner: '',
})
.toCompileTo('Outer');
});
@@ -318,7 +310,7 @@ describe('Regressions', function() {
} else {
return options.inverse(this);
}
}
},
})
.toCompileTo(' 1. IF: John--\n' + ' 2. MYIF: John==\n');
});
@@ -331,7 +323,7 @@ describe('Regressions', function() {
)
.withInput({
listOne: ['a'],
listTwo: ['b']
listTwo: ['b'],
})
.withMessage('')
.toCompileTo('ab');
@@ -342,7 +334,7 @@ describe('Regressions', function() {
var helpers = {
helpa: function (options) {
return options.hash.length;
}
},
};
shouldCompileTo('{{helpa length="foo"}}', [obj, helpers], 'foo');
@@ -354,7 +346,7 @@ describe('Regressions', function() {
)
.withInput({
value: 'parent',
list: [null, 'a']
list: [null, 'a'],
})
.withMessage('')
.toCompileTo('parent=parent parent=parent ');
@@ -365,7 +357,7 @@ describe('Regressions', function() {
.withPartials({
partialWithBlock:
'{{#if @partial-block}} block {{> @partial-block}} block {{/if}}',
partial: '{{#> partialWithBlock}} partial {{/partialWithBlock}}'
partial: '{{#> partialWithBlock}} partial {{/partialWithBlock}}',
})
.toCompileTo('template block partial block template');
});
@@ -379,7 +371,7 @@ describe('Regressions', function() {
return value.toUpperCase();
});
var result = newHandlebarsInstance.templates['test.hbs']({
name: 'yehuda'
name: 'yehuda',
});
equals(result.trim(), 'YEHUDA');
});
@@ -409,7 +401,7 @@ describe('Regressions', function() {
expect(
newHandlebarsInstance.templates['test.hbs']({
property: 'a',
test: { a: 'b' }
test: { a: 'b' },
})
).to.equal('b');
});
@@ -438,7 +430,7 @@ describe('Regressions', function() {
) + '\n\n'
);
},
useData: true
useData: true,
};
}
@@ -455,12 +447,12 @@ describe('Regressions', function() {
{
name: 'lookup',
hash: {},
data: data
data: data,
}
)
);
},
useData: true
useData: true,
};
}
});
@@ -471,7 +463,7 @@ describe('Regressions', function() {
.withHelpers({
helpa: function (options) {
return options.hash.length;
}
},
})
.toCompileTo('foo');
});
@@ -493,7 +485,7 @@ describe('Regressions', function() {
it('should only compile global partials once', function () {
var templateSpy = sinon.spy(newHandlebarsInstance, 'template');
newHandlebarsInstance.registerPartial({
dude: 'I am a partial'
dude: 'I am a partial',
});
var string = 'Dudes: {{> dude}} {{> dude}}';
newHandlebarsInstance.compile(string)(); // This should compile template + partial once
+3 -3
View File
@@ -28,7 +28,7 @@ describe('runtime', function() {
function () {
Handlebars.template({
main: {},
compiler: [Handlebars.COMPILER_REVISION + 1]
compiler: [Handlebars.COMPILER_REVISION + 1],
});
},
Error,
@@ -38,7 +38,7 @@ describe('runtime', function() {
function () {
Handlebars.template({
main: {},
compiler: [Handlebars.LAST_COMPATIBLE_COMPILER_REVISION - 1]
compiler: [Handlebars.LAST_COMPATIBLE_COMPILER_REVISION - 1],
});
},
Error,
@@ -47,7 +47,7 @@ describe('runtime', function() {
shouldThrow(
function () {
Handlebars.template({
main: {}
main: {},
});
},
Error,
+21 -25
View File
@@ -5,9 +5,7 @@ describe('security issues', function() {
.withInput({})
.toCompileTo('');
expectTemplate('{{constructor.name}}')
.withInput({})
.toCompileTo('');
expectTemplate('{{constructor.name}}').withInput({}).toCompileTo('');
});
it('GH-1603: should not allow constructors to be accessed (lookup via toString)', function () {
@@ -57,7 +55,7 @@ describe('security issues', function() {
template({
fn: function () {
functionCalls.push('called');
}
},
});
}).to.throw(Error);
expect(functionCalls.length).to.equal(0);
@@ -68,7 +66,7 @@ describe('security issues', function() {
.withInput({
fn: function () {
return 'functionInData';
}
},
})
.toThrow(Error);
});
@@ -94,7 +92,7 @@ describe('security issues', function() {
{
fn: function () {
functionCalls.push('called');
}
},
},
{ allowCallsToHelperMissing: true }
);
@@ -138,22 +136,20 @@ describe('security issues', function() {
'{{lookup this "__defineGetter__"}}',
'{{lookup this "__defineSetter__"}}',
'{{lookup this "__lookupGetter__"}}',
'{{lookup this "__proto__"}}'
'{{lookup this "__proto__"}}',
];
templates.forEach(function (template) {
describe('access should be denied to ' + template, function () {
it('by default', function () {
expectTemplate(template)
.withInput({})
.toCompileTo('');
expectTemplate(template).withInput({}).toCompileTo('');
});
it(' with proto-access enabled', function () {
expectTemplate(template)
.withInput({})
.withRuntimeOptions({
allowProtoPropertiesByDefault: true,
allowProtoMethodsByDefault: true
allowProtoMethodsByDefault: true,
})
.toCompileTo('');
});
@@ -221,8 +217,8 @@ describe('security issues', function() {
.withCompileOptions(compileOptions)
.withRuntimeOptions({
allowedProtoMethods: {
aMethod: true
}
aMethod: true,
},
})
.toCompileTo('returnValue');
@@ -236,7 +232,7 @@ describe('security issues', function() {
.withInput(new TestClass())
.withCompileOptions(compileOptions)
.withRuntimeOptions({
allowProtoMethodsByDefault: true
allowProtoMethodsByDefault: true,
})
.toCompileTo('returnValue');
@@ -250,7 +246,7 @@ describe('security issues', function() {
.withInput(new TestClass())
.withCompileOptions(compileOptions)
.withRuntimeOptions({
allowProtoMethodsByDefault: false
allowProtoMethodsByDefault: false,
})
.toCompileTo('');
@@ -264,8 +260,8 @@ describe('security issues', function() {
.withRuntimeOptions({
allowProtoMethodsByDefault: true,
allowedProtoMethods: {
aMethod: false
}
aMethod: false,
},
})
.toCompileTo('');
});
@@ -284,8 +280,8 @@ describe('security issues', function() {
.withCompileOptions({ compat: true })
.withRuntimeOptions({
allowedProtoMethods: {
trim: true
}
trim: true,
},
})
.toCompileTo('abc');
});
@@ -322,7 +318,7 @@ describe('security issues', function() {
.withInput(new TestClass())
.withCompileOptions(compileOptions)
.withRuntimeOptions({
allowProtoPropertiesByDefault: false
allowProtoPropertiesByDefault: false,
})
.toCompileTo('');
@@ -337,8 +333,8 @@ describe('security issues', function() {
.withCompileOptions(compileOptions)
.withRuntimeOptions({
allowedProtoProperties: {
aProperty: true
}
aProperty: true,
},
})
.toCompileTo('propertyValue');
@@ -352,7 +348,7 @@ describe('security issues', function() {
.withInput(new TestClass())
.withCompileOptions(compileOptions)
.withRuntimeOptions({
allowProtoPropertiesByDefault: true
allowProtoPropertiesByDefault: true,
})
.toCompileTo('propertyValue');
@@ -366,8 +362,8 @@ describe('security issues', function() {
.withRuntimeOptions({
allowProtoPropertiesByDefault: true,
allowedProtoProperties: {
aProperty: false
}
aProperty: false,
},
})
.toCompileTo('');
});
+3 -3
View File
@@ -15,7 +15,7 @@ describe('source-map', function() {
it('should safely include source map info', function () {
var template = Handlebars.precompile('{{hello}}', {
destName: 'dest.js',
srcName: 'src.hbs'
srcName: 'src.hbs',
});
equal(!!template.code, true);
@@ -26,7 +26,7 @@ describe('source-map', function() {
' b{{hello}} \n {{bar}}a {{#block arg hash=(subex 1 subval)}}{{/block}}',
template = Handlebars.precompile(templateSource, {
destName: 'dest.js',
srcName: 'src.hbs'
srcName: 'src.hbs',
});
if (template.map) {
@@ -49,7 +49,7 @@ function grepLine(token, lines) {
if (column >= 0) {
return {
line: i + 1,
column: column
column: column,
};
}
}
+2 -2
View File
@@ -7,7 +7,7 @@ describe('spec', function() {
var fs = require('fs');
var specDir = __dirname + '/mustache/specs/';
var specs = fs.readdirSync(specDir).filter(name => /.*\.json$/.test(name));
var specs = fs.readdirSync(specDir).filter((name) => /.*\.json$/.test(name));
specs.forEach(function (name) {
var spec = require(specDir + name);
@@ -21,7 +21,7 @@ describe('spec', function() {
// We nest the entire response from partials, not just the literals
(name === 'partials.json' && test.name === 'Standalone Indentation') ||
/\{\{=/.test(test.template) ||
Object.values(test.partials || {}).some(value => /\{\{=/.test(value))
Object.values(test.partials || {}).some((value) => /\{\{=/.test(value))
) {
it.skip(name + ' - ' + test.name);
return;
+5 -5
View File
@@ -31,7 +31,7 @@ describe('strict', function() {
expectTemplate('{{hello}}')
.withCompileOptions({
strict: true,
knownHelpersOnly: true
knownHelpersOnly: true,
})
.toThrow(Exception, /"hello" not defined in/);
});
@@ -44,7 +44,7 @@ describe('strict', function() {
it('should error on missing data lookup', function () {
var xt = expectTemplate('{{@hello}}').withCompileOptions({
strict: true
strict: true,
});
xt.toThrow(Error);
@@ -88,14 +88,14 @@ describe('strict', function() {
it('should allow undefined hash when passed to helpers', function () {
expectTemplate('{{helper value=@foo}}')
.withCompileOptions({
strict: true
strict: true,
})
.withHelpers({
helper: function (options) {
equals('value' in options.hash, true);
equals(options.hash.value, undefined);
return 'success';
}
},
})
.toCompileTo('success');
});
@@ -109,7 +109,7 @@ describe('strict', function() {
it('should error contains correct location properties on missing property lookup', function () {
try {
var template = CompilerContext.compile('\n\n\n {{hello}}', {
strict: true
strict: true,
});
template({});
} catch (error) {
+16 -16
View File
@@ -7,7 +7,7 @@ describe('subexpressions', function() {
},
bar: function () {
return 'LOL';
}
},
})
.toCompileTo('LOLLOL!');
});
@@ -21,7 +21,7 @@ describe('subexpressions', function() {
},
equal: function (x, y) {
return x === y;
}
},
})
.toCompileTo('val is true');
});
@@ -35,7 +35,7 @@ describe('subexpressions', function() {
},
equal: function (x, y) {
return x === y;
}
},
})
.toCompileTo('val is foo!, true and bar!');
});
@@ -49,7 +49,7 @@ describe('subexpressions', function() {
},
equal: function (x, y) {
return x === y;
}
},
})
.toCompileTo('val is true');
});
@@ -62,7 +62,7 @@ describe('subexpressions', function() {
},
concat: function (a, b) {
return a + b;
}
},
};
expectTemplate("{{dash 'abc' (concat a b)}}")
@@ -100,7 +100,7 @@ describe('subexpressions', function() {
}
lastOptions = options;
return x === y;
}
},
};
expectTemplate('{{equal (equal true true) true}}')
.withHelpers(helpers)
@@ -116,7 +116,7 @@ describe('subexpressions', function() {
},
equal: function (x, y) {
return x === y;
}
},
})
.toCompileTo('val is true');
});
@@ -129,7 +129,7 @@ describe('subexpressions', function() {
},
equal: function (x, y) {
return x === y;
}
},
})
.toCompileTo('val is true');
});
@@ -153,7 +153,7 @@ describe('subexpressions', function() {
},
t: function (defaultString) {
return new Handlebars.SafeString(defaultString);
}
},
})
.toCompileTo('<input aria-label="Name" placeholder="Example User" />');
});
@@ -165,8 +165,8 @@ describe('subexpressions', function() {
.withInput({
item: {
field: 'Name',
placeholder: 'Example User'
}
placeholder: 'Example User',
},
})
.withHelpers({
input: function (options) {
@@ -183,7 +183,7 @@ describe('subexpressions', function() {
},
t: function (defaultString) {
return new Handlebars.SafeString(defaultString);
}
},
})
.toCompileTo('<input aria-label="Name" placeholder="Example User" />');
});
@@ -193,12 +193,12 @@ describe('subexpressions', function() {
.withInput({
bar: function () {
return 'LOL';
}
},
})
.withHelpers({
foo: function (val) {
return val + val;
}
},
})
.toCompileTo('LOLLOL!');
});
@@ -206,12 +206,12 @@ describe('subexpressions', function() {
it("subexpressions can't just be property lookups", function () {
expectTemplate('{{foo (bar)}}!')
.withInput({
bar: 'LOL'
bar: 'LOL',
})
.withHelpers({
foo: function (val) {
return val + val;
}
},
})
.toThrow();
});
+37 -37
View File
@@ -63,7 +63,7 @@ describe('Tokenizer', function() {
'CONTENT',
'OPEN',
'ID',
'CLOSE'
'CLOSE',
]);
shouldBeToken(result[3], 'CONTENT', ' ');
@@ -78,7 +78,7 @@ describe('Tokenizer', function() {
'CLOSE',
'CONTENT',
'CONTENT',
'CONTENT'
'CONTENT',
]);
shouldBeToken(result[3], 'CONTENT', ' ');
@@ -96,7 +96,7 @@ describe('Tokenizer', function() {
'CONTENT',
'OPEN',
'ID',
'CLOSE'
'CLOSE',
]);
shouldBeToken(result[4], 'CONTENT', '{{{bar}}} ');
@@ -115,7 +115,7 @@ describe('Tokenizer', function() {
'CONTENT',
'OPEN',
'ID',
'CLOSE'
'CLOSE',
]);
shouldBeToken(result[3], 'CONTENT', ' \\');
@@ -135,7 +135,7 @@ describe('Tokenizer', function() {
'CONTENT',
'OPEN',
'ID',
'CLOSE'
'CLOSE',
]);
shouldBeToken(result[3], 'CONTENT', ' \\');
@@ -156,7 +156,7 @@ describe('Tokenizer', function() {
'CLOSE',
'CONTENT',
'CONTENT',
'CONTENT'
'CONTENT',
]);
shouldBeToken(result[3], 'CONTENT', ' \\');
@@ -177,7 +177,7 @@ describe('Tokenizer', function() {
'CONTENT',
'OPEN',
'ID',
'CLOSE'
'CLOSE',
]);
shouldBeToken(result[4], 'CONTENT', '{{bar}} ');
@@ -199,7 +199,7 @@ describe('Tokenizer', function() {
'CONTENT',
'OPEN',
'ID',
'CLOSE'
'CLOSE',
]);
shouldBeToken(result[3], 'CONTENT', ' \\');
@@ -222,7 +222,7 @@ describe('Tokenizer', function() {
'ID',
'SEP',
'ID',
'CLOSE'
'CLOSE',
]);
});
@@ -243,7 +243,7 @@ describe('Tokenizer', function() {
'ID',
'SEP',
'ID',
'CLOSE'
'CLOSE',
]);
});
@@ -266,7 +266,7 @@ describe('Tokenizer', function() {
'ID',
'SEP',
'ID',
'CLOSE'
'CLOSE',
]);
shouldBeToken(result[1], 'ID', '..');
});
@@ -280,7 +280,7 @@ describe('Tokenizer', function() {
'ID',
'SEP',
'ID',
'CLOSE'
'CLOSE',
]);
shouldBeToken(result[1], 'ID', '..');
});
@@ -340,7 +340,7 @@ describe('Tokenizer', function() {
'ID',
'SEP',
'ID',
'CLOSE'
'CLOSE',
]);
});
@@ -356,7 +356,7 @@ describe('Tokenizer', function() {
'CONTENT',
'OPEN',
'ID',
'CLOSE'
'CLOSE',
]);
shouldBeToken(result[1], 'COMMENT', '{{! this is a comment }}');
});
@@ -369,7 +369,7 @@ describe('Tokenizer', function() {
'CONTENT',
'OPEN',
'ID',
'CLOSE'
'CLOSE',
]);
shouldBeToken(result[1], 'COMMENT', '{{!-- this is a {{comment}} --}}');
});
@@ -384,7 +384,7 @@ describe('Tokenizer', function() {
'CONTENT',
'OPEN',
'ID',
'CLOSE'
'CLOSE',
]);
shouldBeToken(result[1], 'COMMENT', '{{!-- this is a\n{{comment}}\n--}}');
});
@@ -398,7 +398,7 @@ describe('Tokenizer', function() {
'CONTENT',
'OPEN_ENDBLOCK',
'ID',
'CLOSE'
'CLOSE',
]);
});
@@ -410,7 +410,7 @@ describe('Tokenizer', function() {
'CONTENT',
'OPEN_ENDBLOCK',
'ID',
'CLOSE'
'CLOSE',
]);
shouldMatchTokens(tokenize('{{*foo}}'), ['OPEN', 'ID', 'CLOSE']);
});
@@ -518,7 +518,7 @@ describe('Tokenizer', function() {
'ID',
'EQUALS',
'ID',
'CLOSE'
'CLOSE',
]);
result = tokenize('{{ foo bar baz=1 }}');
@@ -529,7 +529,7 @@ describe('Tokenizer', function() {
'ID',
'EQUALS',
'NUMBER',
'CLOSE'
'CLOSE',
]);
result = tokenize('{{ foo bar baz=true }}');
@@ -540,7 +540,7 @@ describe('Tokenizer', function() {
'ID',
'EQUALS',
'BOOLEAN',
'CLOSE'
'CLOSE',
]);
result = tokenize('{{ foo bar baz=false }}');
@@ -551,7 +551,7 @@ describe('Tokenizer', function() {
'ID',
'EQUALS',
'BOOLEAN',
'CLOSE'
'CLOSE',
]);
result = tokenize('{{ foo bar\n baz=bat }}');
@@ -562,7 +562,7 @@ describe('Tokenizer', function() {
'ID',
'EQUALS',
'ID',
'CLOSE'
'CLOSE',
]);
result = tokenize('{{ foo bar baz="bat" }}');
@@ -573,7 +573,7 @@ describe('Tokenizer', function() {
'ID',
'EQUALS',
'STRING',
'CLOSE'
'CLOSE',
]);
result = tokenize('{{ foo bar baz="bat" bam=wot }}');
@@ -587,7 +587,7 @@ describe('Tokenizer', function() {
'ID',
'EQUALS',
'ID',
'CLOSE'
'CLOSE',
]);
result = tokenize('{{foo omg bar=baz bat="bam"}}');
@@ -601,7 +601,7 @@ describe('Tokenizer', function() {
'ID',
'EQUALS',
'STRING',
'CLOSE'
'CLOSE',
]);
shouldBeToken(result[2], 'ID', 'omg');
});
@@ -623,7 +623,7 @@ describe('Tokenizer', function() {
'EQUALS',
'DATA',
'ID',
'CLOSE'
'CLOSE',
]);
shouldBeToken(result[5], 'ID', 'baz');
});
@@ -644,7 +644,7 @@ describe('Tokenizer', function() {
'OPEN_SEXPR',
'ID',
'CLOSE_SEXPR',
'CLOSE'
'CLOSE',
]);
shouldBeToken(result[1], 'ID', 'foo');
shouldBeToken(result[3], 'ID', 'bar');
@@ -657,7 +657,7 @@ describe('Tokenizer', function() {
'ID',
'ID',
'CLOSE_SEXPR',
'CLOSE'
'CLOSE',
]);
shouldBeToken(result[1], 'ID', 'foo');
shouldBeToken(result[3], 'ID', 'a-x');
@@ -679,7 +679,7 @@ describe('Tokenizer', function() {
'OPEN_SEXPR',
'ID',
'CLOSE_SEXPR',
'CLOSE'
'CLOSE',
]);
shouldBeToken(result[3], 'ID', 'bar');
shouldBeToken(result[5], 'ID', 'lol');
@@ -714,7 +714,7 @@ describe('Tokenizer', function() {
'ID',
'STRING',
'CLOSE_SEXPR',
'CLOSE'
'CLOSE',
]);
});
@@ -726,7 +726,7 @@ describe('Tokenizer', function() {
'OPEN_BLOCK_PARAMS',
'ID',
'CLOSE_BLOCK_PARAMS',
'CLOSE'
'CLOSE',
]);
result = tokenize('{{#foo as |bar baz|}}');
@@ -737,7 +737,7 @@ describe('Tokenizer', function() {
'ID',
'ID',
'CLOSE_BLOCK_PARAMS',
'CLOSE'
'CLOSE',
]);
result = tokenize('{{#foo as | bar baz |}}');
@@ -748,7 +748,7 @@ describe('Tokenizer', function() {
'ID',
'ID',
'CLOSE_BLOCK_PARAMS',
'CLOSE'
'CLOSE',
]);
result = tokenize('{{#foo as as | bar baz |}}');
@@ -760,7 +760,7 @@ describe('Tokenizer', function() {
'ID',
'ID',
'CLOSE_BLOCK_PARAMS',
'CLOSE'
'CLOSE',
]);
result = tokenize('{{else foo as |bar baz|}}');
@@ -771,7 +771,7 @@ describe('Tokenizer', function() {
'ID',
'ID',
'CLOSE_BLOCK_PARAMS',
'CLOSE'
'CLOSE',
]);
});
@@ -790,7 +790,7 @@ describe('Tokenizer', function() {
'ID',
'CLOSE_RAW_BLOCK',
'CONTENT',
'END_RAW_BLOCK'
'END_RAW_BLOCK',
]);
});
});
+1 -1
View File
@@ -36,7 +36,7 @@ describe('utils', function() {
var obj = {
toHTML: function () {
return 'foo<&"\'>';
}
},
};
equals(Handlebars.Utils.escapeExpression(obj), 'foo<&"\'>');
});
+5 -15
View File
@@ -2,25 +2,15 @@ describe('whitespace control', function() {
it('should strip whitespace around mustache calls', function () {
var hash = { foo: 'bar<' };
expectTemplate(' {{~foo~}} ')
.withInput(hash)
.toCompileTo('bar&lt;');
expectTemplate(' {{~foo~}} ').withInput(hash).toCompileTo('bar&lt;');
expectTemplate(' {{~foo}} ')
.withInput(hash)
.toCompileTo('bar&lt; ');
expectTemplate(' {{~foo}} ').withInput(hash).toCompileTo('bar&lt; ');
expectTemplate(' {{foo~}} ')
.withInput(hash)
.toCompileTo(' bar&lt;');
expectTemplate(' {{foo~}} ').withInput(hash).toCompileTo(' bar&lt;');
expectTemplate(' {{~&foo~}} ')
.withInput(hash)
.toCompileTo('bar<');
expectTemplate(' {{~&foo~}} ').withInput(hash).toCompileTo('bar<');
expectTemplate(' {{~{foo}~}} ')
.withInput(hash)
.toCompileTo('bar<');
expectTemplate(' {{~{foo}~}} ').withInput(hash).toCompileTo('bar<');
expectTemplate('1\n{{foo~}} \n\n 23\n{{bar}}4').toCompileTo('1\n23\n4');
});
+2 -2
View File
@@ -3,6 +3,6 @@ module.exports = {
'no-process-env': 'off',
'prefer-const': 'warn',
'compat/compat': 'off',
'dot-notation': ['error', { allowKeywords: true }]
}
'dot-notation': ['error', { allowKeywords: true }],
},
};
+2 -2
View File
@@ -8,7 +8,7 @@ module.exports = function(grunt) {
const onlyExecuteName = grunt.option('name');
const events = {};
const promises = Object.keys(metrics).map(async name => {
const promises = Object.keys(metrics).map(async (name) => {
if (/^_/.test(name)) {
return;
}
@@ -16,7 +16,7 @@ module.exports = function(grunt) {
return;
}
return new Promise(resolve => {
return new Promise((resolve) => {
metrics[name](grunt, function (data) {
events[name] = data;
resolve();
+5 -5
View File
@@ -48,7 +48,7 @@ module.exports = function(grunt) {
}
async function publish(suffixes) {
const publishPromises = suffixes.map(suffix => publishSuffix(suffix));
const publishPromises = suffixes.map((suffix) => publishSuffix(suffix));
return Promise.all(publishPromises);
}
@@ -57,9 +57,9 @@ module.exports = function(grunt) {
'handlebars.js',
'handlebars.min.js',
'handlebars.runtime.js',
'handlebars.runtime.min.js'
'handlebars.runtime.min.js',
];
const publishPromises = filenames.map(async filename => {
const publishPromises = filenames.map(async (filename) => {
const nameInBucket = getNameInBucket(filename, suffix);
const localFile = getLocalFile(filename);
await uploadToBucket(localFile, nameInBucket);
@@ -75,7 +75,7 @@ module.exports = function(grunt) {
const uploadParams = {
Bucket: bucket,
Key: nameInBucket,
Body: grunt.file.read(localFile)
Body: grunt.file.read(localFile),
};
return s3PutObject(uploadParams);
}
@@ -84,7 +84,7 @@ module.exports = function(grunt) {
function s3PutObject(uploadParams) {
const s3 = new AWS.S3();
return new Promise((resolve, reject) => {
s3.putObject(uploadParams, err => {
s3.putObject(uploadParams, (err) => {
if (err != null) {
return reject(err);
}
+34 -34
View File
@@ -11,47 +11,47 @@ const testCases = [
{
binInputParameters: ['-a', 'spec/artifacts/empty.handlebars'],
outputLocation: 'stdout',
expectedOutputSpec: './spec/expected/empty.amd.js'
expectedOutputSpec: './spec/expected/empty.amd.js',
},
{
binInputParameters: [
'-a',
'-f',
'TEST_OUTPUT',
'spec/artifacts/empty.handlebars'
'spec/artifacts/empty.handlebars',
],
outputLocation: 'TEST_OUTPUT',
expectedOutputSpec: './spec/expected/empty.amd.js'
expectedOutputSpec: './spec/expected/empty.amd.js',
},
{
binInputParameters: [
'-a',
'-n',
'CustomNamespace.templates',
'spec/artifacts/empty.handlebars'
'spec/artifacts/empty.handlebars',
],
outputLocation: 'stdout',
expectedOutputSpec: './spec/expected/empty.amd.namespace.js'
expectedOutputSpec: './spec/expected/empty.amd.namespace.js',
},
{
binInputParameters: [
'-a',
'--namespace',
'CustomNamespace.templates',
'spec/artifacts/empty.handlebars'
'spec/artifacts/empty.handlebars',
],
outputLocation: 'stdout',
expectedOutputSpec: './spec/expected/empty.amd.namespace.js'
expectedOutputSpec: './spec/expected/empty.amd.namespace.js',
},
{
binInputParameters: ['-a', '-s', 'spec/artifacts/empty.handlebars'],
outputLocation: 'stdout',
expectedOutputSpec: './spec/expected/empty.amd.simple.js'
expectedOutputSpec: './spec/expected/empty.amd.simple.js',
},
{
binInputParameters: ['-a', '-m', 'spec/artifacts/empty.handlebars'],
outputLocation: 'stdout',
expectedOutputSpec: './spec/expected/empty.amd.min.js'
expectedOutputSpec: './spec/expected/empty.amd.min.js',
},
{
binInputParameters: [
@@ -61,44 +61,44 @@ const testCases = [
'someHelper',
'-k',
'anotherHelper',
'-o'
'-o',
],
outputLocation: 'stdout',
expectedOutputSpec: './spec/expected/non.empty.amd.known.helper.js'
expectedOutputSpec: './spec/expected/non.empty.amd.known.helper.js',
},
{
binInputParameters: ['--help'],
outputLocation: 'stdout',
expectedOutputSpec: './spec/expected/help.menu.txt'
expectedOutputSpec: './spec/expected/help.menu.txt',
},
{
binInputParameters: ['-v'],
outputLocation: 'stdout',
expectedOutput: require('../package.json').version
expectedOutput: require('../package.json').version,
},
{
binInputParameters: [
'-a',
'-e',
'hbs',
'./spec/artifacts/non.default.extension.hbs'
'./spec/artifacts/non.default.extension.hbs',
],
outputLocation: 'stdout',
expectedOutputSpec: './spec/expected/non.default.extension.amd.js'
expectedOutputSpec: './spec/expected/non.default.extension.amd.js',
},
{
binInputParameters: [
'-a',
'-p',
'./spec/artifacts/partial.template.handlebars'
'./spec/artifacts/partial.template.handlebars',
],
outputLocation: 'stdout',
expectedOutputSpec: './spec/expected/partial.template.js'
expectedOutputSpec: './spec/expected/partial.template.js',
},
{
binInputParameters: ['spec/artifacts/empty.handlebars', '-c'],
outputLocation: 'stdout',
expectedOutputSpec: './spec/expected/empty.common.js'
expectedOutputSpec: './spec/expected/empty.common.js',
},
{
binInputParameters: [
@@ -106,30 +106,30 @@ const testCases = [
'spec/artifacts/empty.handlebars',
'-a',
'-n',
'someNameSpace'
'someNameSpace',
],
outputLocation: 'stdout',
expectedOutputSpec: './spec/expected/namespace.amd.js'
expectedOutputSpec: './spec/expected/namespace.amd.js',
},
{
binInputParameters: [
'spec/artifacts/empty.handlebars',
'-h',
'some-path/',
'-a'
'-a',
],
outputLocation: 'stdout',
expectedOutputSpec: './spec/expected/handlebar.path.amd.js'
expectedOutputSpec: './spec/expected/handlebar.path.amd.js',
},
{
binInputParameters: [
'spec/artifacts/partial.template.handlebars',
'-r',
'spec',
'-a'
'-a',
],
outputLocation: 'stdout',
expectedOutputSpec: './spec/expected/empty.root.amd.js'
expectedOutputSpec: './spec/expected/empty.root.amd.js',
},
{
binInputParameters: [
@@ -141,10 +141,10 @@ const testCases = [
'firstTemplate',
'-N',
'secondTemplate',
'-a'
'-a',
],
outputLocation: 'stdout',
expectedOutputSpec: './spec/expected/empty.name.amd.js'
expectedOutputSpec: './spec/expected/empty.name.amd.js',
},
{
binInputParameters: [
@@ -155,26 +155,26 @@ const testCases = [
'-N',
'test',
'--map',
'./spec/tmp/source.map.amd.txt'
'./spec/tmp/source.map.amd.txt',
],
outputLocation: 'stdout',
expectedOutputSpec: './spec/expected/source.map.amd.js'
expectedOutputSpec: './spec/expected/source.map.amd.js',
},
{
binInputParameters: ['./spec/artifacts/bom.handlebars', '-b', '-a'],
outputLocation: 'stdout',
expectedOutputSpec: './spec/expected/bom.amd.js'
expectedOutputSpec: './spec/expected/bom.amd.js',
},
// Issue #1673
{
binInputParameters: [
'--amd',
'--no-amd',
'spec/artifacts/empty.handlebars'
'spec/artifacts/empty.handlebars',
],
outputLocation: 'stdout',
expectedOutputSpec: './spec/expected/empty.common.js'
}
expectedOutputSpec: './spec/expected/empty.common.js',
},
];
module.exports = function (grunt) {
@@ -184,7 +184,7 @@ module.exports = function(grunt) {
binInputParameters,
outputLocation,
expectedOutputSpec,
expectedOutput
expectedOutput,
}) => {
const stdout = executeBinHandlebars(...binInputParameters);
@@ -205,7 +205,7 @@ module.exports = function(grunt) {
expect(normalizedOutput).not.to.be.differentFrom(
normalizedExpectedOutput,
{
relaxedSpace: true
relaxedSpace: true,
}
);
}
+1 -1
View File
@@ -12,7 +12,7 @@ module.exports = function(grunt) {
registerAsyncTask('test:cov', async () =>
execNodeJsScriptWithInheritedOutput('node_modules/nyc/bin/nyc', [
nodeJs,
'./spec/env/runner.js'
'./spec/env/runner.js',
])
);
+2 -2
View File
@@ -1,5 +1,5 @@
module.exports = {
env: {
mocha: true
}
mocha: true,
},
};
+2 -2
View File
@@ -48,7 +48,7 @@ describe('utils/git', function() {
'origin\thttps://test.org/test (fetch)',
'origin\thttps://test.org/test (push)',
'second-remote\thttps://test.org/test2 (fetch)',
'second-remote\thttps://test.org/test2 (push)'
'second-remote\thttps://test.org/test2 (push)',
]);
});
});
@@ -64,7 +64,7 @@ describe('utils/git', function() {
' test',
' test2',
' remotes/origin/HEAD -> origin/master',
' remotes/origin/master'
' remotes/origin/master',
]);
});
});
+1 -1
View File
@@ -4,7 +4,7 @@ function createRegisterAsyncTaskFn(grunt) {
return function registerAsyncTask(name, asyncFunction) {
grunt.registerTask(name, function () {
asyncFunction()
.catch(error => {
.catch((error) => {
grunt.fatal(error);
})
.finally(this.async());
+2 -2
View File
@@ -1,13 +1,13 @@
const childProcess = require('child_process');
module.exports = {
execNodeJsScriptWithInheritedOutput
execNodeJsScriptWithInheritedOutput,
};
async function execNodeJsScriptWithInheritedOutput(command, args) {
return new Promise((resolve, reject) => {
const child = childProcess.fork(command, args, { stdio: 'inherit' });
child.on('close', code => {
child.on('close', (code) => {
if (code !== 0) {
reject(new Error(`Child process failed with exit-code ${code}`));
}
+3 -3
View File
@@ -14,7 +14,7 @@ module.exports = {
headSha,
masterSha,
tagName: await getTagName(),
isMaster: headSha === masterSha
isMaster: headSha === masterSha,
};
},
async add(path) {
@@ -23,7 +23,7 @@ module.exports = {
async commit(message) {
return git('commit', '--message', message);
},
git // visible for testing
git, // visible for testing
};
async function getHeadSha() {
@@ -52,7 +52,7 @@ async function getTagName() {
}
const tags = trimmedStdout.split(/\n|\r\n/);
const versionTags = tags.filter(tag => /^v/.test(tag));
const versionTags = tags.filter((tag) => /^v/.test(tag));
if (versionTags[0] != null) {
return versionTags[0];
}
+6 -6
View File
@@ -22,27 +22,27 @@ module.exports = function(grunt) {
{
path: 'lib/handlebars/base.js',
regex: /const VERSION = ['"](.*)['"];/,
replacement: `const VERSION = '${version}';`
replacement: `const VERSION = '${version}';`,
},
{
path: 'components/bower.json',
regex: /"version":.*/,
replacement: `"version": "${version}",`
replacement: `"version": "${version}",`,
},
{
path: 'components/package.json',
regex: /"version":.*/,
replacement: `"version": "${version}",`
replacement: `"version": "${version}",`,
},
{
path: 'components/handlebars.js.nuspec',
regex: /<version>.*<\/version>/,
replacement: `<version>${version}</version>`
}
replacement: `<version>${version}</version>`,
},
];
await Promise.all(
replaceSpec.map(replaceSpec =>
replaceSpec.map((replaceSpec) =>
replaceAndAdd(
replaceSpec.path,
replaceSpec.regex,
+2 -2
View File
@@ -1,6 +1,6 @@
module.exports = {
rules: {
'no-console': 'off',
'no-var': 'off'
}
'no-var': 'off',
},
};
+1 -1
View File
@@ -11,7 +11,7 @@ module.exports = function(grunt, callback) {
compiled = Handlebars.precompile(src, {}),
knownHelpers = Handlebars.precompile(src, {
knownHelpersOnly: true,
knownHelpers: info.helpers
knownHelpers: info.helpers,
});
templateSizes[template] = compiled.length;
+3 -3
View File
@@ -2,12 +2,12 @@ module.exports = {
helpers: {
foo: function () {
return '';
}
},
},
context: {
bar: true
bar: true,
},
handlebars:
'{{foo person "person" 1 true foo=bar foo="person" foo=1 foo=true}}'
'{{foo person "person" 1 true foo=bar foo="person" foo=1 foo=true}}',
};
+3 -3
View File
@@ -4,10 +4,10 @@ module.exports = {
{ name: 'Moe' },
{ name: 'Larry' },
{ name: 'Curly' },
{ name: 'Shemp' }
]
{ name: 'Shemp' },
],
},
handlebars: '{{#each names}}{{name}}{{/each}}',
dust: '{#names}{name}{/names}',
mustache: '{{#names}}{{name}}{{/names}}'
mustache: '{{#names}}{{name}}{{/names}}',
};
+3 -3
View File
@@ -4,8 +4,8 @@ module.exports = {
{ name: 'Moe' },
{ name: 'Larry' },
{ name: 'Curly' },
{ name: 'Shemp' }
]
{ name: 'Shemp' },
],
},
handlebars: '{{#names}}{{name}}{{/names}}'
handlebars: '{{#names}}{{name}}{{/names}}',
};
+3 -3
View File
@@ -9,11 +9,11 @@ module.exports = {
items: [
{ name: 'red', current: true, url: '#Red' },
{ name: 'green', current: false, url: '#Green' },
{ name: 'blue', current: false, url: '#Blue' }
]
{ name: 'blue', current: false, url: '#Blue' },
],
},
handlebars: fs.readFileSync(__dirname + '/complex.handlebars').toString(),
dust: fs.readFileSync(__dirname + '/complex.dust').toString(),
mustache: fs.readFileSync(__dirname + '/complex.mustache').toString()
mustache: fs.readFileSync(__dirname + '/complex.mustache').toString(),
};
+3 -3
View File
@@ -4,8 +4,8 @@ module.exports = {
{ name: 'Moe' },
{ name: 'Larry' },
{ name: 'Curly' },
{ name: 'Shemp' }
]
{ name: 'Shemp' },
],
},
handlebars: '{{#each names}}{{@index}}{{name}}{{/each}}'
handlebars: '{{#each names}}{{@index}}{{name}}{{/each}}',
};
+3 -3
View File
@@ -4,10 +4,10 @@ module.exports = {
{ name: 'Moe' },
{ name: 'Larry' },
{ name: 'Curly' },
{ name: 'Shemp' }
{ name: 'Shemp' },
],
foo: 'bar'
foo: 'bar',
},
handlebars: '{{#each names}}{{../foo}}{{/each}}',
mustache: '{{#names}}{{foo}}{{/names}}'
mustache: '{{#names}}{{foo}}{{/names}}',
};
+3 -3
View File
@@ -4,11 +4,11 @@ module.exports = {
{ bat: 'foo', name: ['Moe'] },
{ bat: 'foo', name: ['Larry'] },
{ bat: 'foo', name: ['Curly'] },
{ bat: 'foo', name: ['Shemp'] }
{ bat: 'foo', name: ['Shemp'] },
],
foo: 'bar'
foo: 'bar',
},
handlebars:
'{{#each names}}{{#each name}}{{../bat}}{{../../foo}}{{/each}}{{/each}}',
mustache: '{{#names}}{{#name}}{{bat}}{{foo}}{{/name}}{{/names}}'
mustache: '{{#names}}{{#name}}{{bat}}{{foo}}{{/name}}{{/names}}',
};
+1 -1
View File
@@ -1,4 +1,4 @@
module.exports = {
context: { person: { name: 'Larry', age: 45 } },
handlebars: '{{#person}}{{name}}{{age}}{{/person}}'
handlebars: '{{#person}}{{name}}{{age}}{{/person}}',
};
+1 -1
View File
@@ -2,5 +2,5 @@ module.exports = {
context: { person: { name: 'Larry', age: 45 } },
handlebars: '{{#with person}}{{name}}{{age}}{{/with}}',
dust: '{#person}{name}{age}{/person}',
mustache: '{{#person}}{{name}}{{age}}{{/person}}'
mustache: '{{#person}}{{name}}{{age}}{{/person}}',
};
+3 -3
View File
@@ -1,13 +1,13 @@
module.exports = {
context: {
name: '1',
kids: [{ name: '1.1', kids: [{ name: '1.1.1', kids: [] }] }]
kids: [{ name: '1.1', kids: [{ name: '1.1.1', kids: [] }] }],
},
partials: {
mustache: { recursion: '{{name}}{{#kids}}{{>recursion}}{{/kids}}' },
handlebars: { recursion: '{{name}}{{#each kids}}{{>recursion}}{{/each}}' }
handlebars: { recursion: '{{name}}{{#each kids}}{{>recursion}}{{/each}}' },
},
handlebars: '{{name}}{{#each kids}}{{>recursion}}{{/each}}',
dust: '{name}{#kids}{>recursion:./}{/kids}',
mustache: '{{name}}{{#kids}}{{>recursion}}{{/kids}}'
mustache: '{{name}}{{#kids}}{{>recursion}}{{/kids}}',
};
+5 -5
View File
@@ -3,17 +3,17 @@ module.exports = {
peeps: [
{ name: 'Moe', count: 15 },
{ name: 'Larry', count: 5 },
{ name: 'Curly', count: 1 }
]
{ name: 'Curly', count: 1 },
],
},
partials: {
mustache: { variables: 'Hello {{name}}! You have {{count}} new messages.' },
handlebars: {
variables: 'Hello {{name}}! You have {{count}} new messages.'
}
variables: 'Hello {{name}}! You have {{count}} new messages.',
},
},
handlebars: '{{#each peeps}}{{>variables}}{{/each}}',
dust: '{#peeps}{>variables/}{/peeps}',
mustache: '{{#peeps}}{{>variables}}{{/peeps}}'
mustache: '{{#peeps}}{{>variables}}{{/peeps}}',
};
+1 -1
View File
@@ -3,5 +3,5 @@ module.exports = {
handlebars:
'{{person.name.bar.baz}}{{person.age}}{{person.foo}}{{animal.age}}',
dust: '{person.name.bar.baz}{person.age}{person.foo}{animal.age}',
mustache: '{{person.name.bar.baz}}{{person.age}}{{person.foo}}{{animal.age}}'
mustache: '{{person.name.bar.baz}}{{person.age}}{{person.foo}}{{animal.age}}',
};
+1 -1
View File
@@ -2,5 +2,5 @@ module.exports = {
context: {},
handlebars: 'Hello world',
dust: 'Hello world',
mustache: 'Hello world'
mustache: 'Hello world',
};
+2 -2
View File
@@ -5,9 +5,9 @@ module.exports = {
},
header: function () {
return 'Colors';
}
},
handlebars: '{{echo (header)}}'
},
handlebars: '{{echo (header)}}',
};
module.exports.context = module.exports.helpers;
+1 -1
View File
@@ -2,5 +2,5 @@ module.exports = {
context: { name: 'Mick', count: 30 },
handlebars: 'Hello {{name}}! You have {{count}} new messages.',
dust: 'Hello {name}! You have {count} new messages.',
mustache: 'Hello {{name}}! You have {{count}} new messages.'
mustache: 'Hello {{name}}! You have {{count}} new messages.',
};
+6 -6
View File
@@ -33,18 +33,18 @@ function makeSuite(bench, name, template, handlebarsOnly) {
var handlebar = Handlebars.compile(template.handlebars, { data: false }),
compat = Handlebars.compile(template.handlebars, {
data: false,
compat: true
compat: true,
}),
options = { helpers: template.helpers };
_.each(template.partials && template.partials.handlebars, function(
partial,
partialName
) {
_.each(
template.partials && template.partials.handlebars,
function (partial, partialName) {
Handlebars.registerPartial(
partialName,
Handlebars.compile(partial, { data: false })
);
});
}
);
handlebarsOut = handlebar(context, options);
bench('handlebars', function () {
+8 -7
View File
@@ -47,7 +47,7 @@ BenchWarmer.prototype = {
},
onError: function () {
self.errors[this.name] = this;
}
},
});
bench.suiteName = this.suiteName;
bench.benchName = name;
@@ -107,7 +107,7 @@ BenchWarmer.prototype = {
}
callback();
}
},
});
console.log('\n');
@@ -169,11 +169,12 @@ BenchWarmer.prototype = {
},
startLine: function (name) {
var winners = Benchmark.map(this.winners(this.currentBenches), function(
bench
) {
var winners = Benchmark.map(
this.winners(this.currentBenches),
function (bench) {
return bench.name.split(': ')[1];
});
}
);
this.currentBenches = [];
@@ -215,7 +216,7 @@ BenchWarmer.prototype = {
var padding = this.benchSize - out.length + 1;
out = out + new Array(padding).join(' ');
console.log(out);
}
},
};
module.exports = BenchWarmer;
+2 -2
View File
@@ -1,5 +1,5 @@
module.exports = {
parserOptions: {
ecmaVersion: 2018
}
ecmaVersion: 2018,
},
};
+6 -6
View File
@@ -5,23 +5,23 @@ const config = {
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] }
use: { ...devices['Desktop Chrome'] },
},
{
name: 'firefox',
use: { ...devices['Desktop Firefox'] }
use: { ...devices['Desktop Firefox'] },
},
{
name: 'webkit',
use: { ...devices['Desktop Safari'] }
}
use: { ...devices['Desktop Safari'] },
},
],
reporter: 'list',
webServer: {
command: 'npm run test:serve',
port: 9999,
reuseExistingServer: false
}
reuseExistingServer: false,
},
};
module.exports = config;
@@ -1,6 +1,6 @@
module.exports = {
rules: {
'no-console': 'off',
'no-var': 'off'
}
'no-var': 'off',
},
};
@@ -4,7 +4,7 @@ export default {
input: 'src/index.js',
output: {
file: 'dist/bundle.js',
format: 'es'
format: 'es',
},
plugins: [nodeResolve()]
plugins: [nodeResolve()],
};
@@ -3,10 +3,10 @@ module.exports = {
root: true,
extends: ['eslint:recommended', 'prettier'],
env: {
browser: true
browser: true,
},
parserOptions: {
sourceType: 'module',
ecmaVersion: 6
}
ecmaVersion: 6,
},
};
@@ -3,8 +3,8 @@ const fs = require('fs');
const testFiles = fs.readdirSync('src');
const entryPoints = {};
testFiles
.filter(file => file.match(/-test.js$/))
.forEach(file => {
.filter((file) => file.match(/-test.js$/))
.forEach((file) => {
entryPoints[file] = `./src/${file}`;
});
@@ -13,7 +13,7 @@ module.exports = {
mode: 'production',
output: {
filename: '[name]',
path: __dirname + '/dist'
path: __dirname + '/dist',
},
module: {
rules: [
@@ -22,12 +22,12 @@ module.exports = {
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: { cacheDirectory: false }
}
}
]
options: { cacheDirectory: false },
},
},
],
},
optimization: {
minimize: false
}
minimize: false,
},
};
@@ -3,10 +3,10 @@ module.exports = {
extends: ['eslint:recommended', 'prettier'],
env: {
node: true,
browser: true
browser: true,
},
parserOptions: {
sourceType: 'module',
ecmaVersion: 6
}
ecmaVersion: 6,
},
};
@@ -31,13 +31,13 @@ const template = Handlebars.template({
data: data,
loc: {
start: { line: 1, column: 8 },
end: { line: 1, column: 18 }
}
end: { line: 1, column: 18 },
},
})
: helper)
)
);
},
useData: true
useData: true,
});
assertEquals(template({ author: 'Yehuda' }), 'Author: Yehuda');
@@ -3,8 +3,8 @@ const fs = require('fs');
const testFiles = fs.readdirSync('src');
const entryPoints = {};
testFiles
.filter(file => file.match(/-test.js$/))
.forEach(file => {
.filter((file) => file.match(/-test.js$/))
.forEach((file) => {
entryPoints[file] = `./src/${file}`;
});
@@ -13,9 +13,9 @@ module.exports = {
mode: 'production',
output: {
filename: '[name]',
path: __dirname + '/dist'
path: __dirname + '/dist',
},
module: {
rules: [{ test: /\.handlebars$/, loader: 'handlebars-loader' }]
}
rules: [{ test: /\.handlebars$/, loader: 'handlebars-loader' }],
},
};
+2 -2
View File
@@ -16,7 +16,7 @@ var template = Handlebars.precompile(script, {
compat: false,
strict: true,
trackIds: true,
knownHelpersOnly: false
knownHelpersOnly: false,
});
if (!verbose) {
@@ -67,7 +67,7 @@ if (!verbose) {
ordered.push({
startLine: last[lineName],
startCol: last[colName],
endLine: current && current[lineName]
endLine: current && current[lineName],
});
}
last = current;