diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs index a6ae06ee..94def1e5 100644 --- a/.git-blame-ignore-revs +++ b/.git-blame-ignore-revs @@ -1,2 +1,4 @@ # Upgrade to Prettier 2.7 -3d228334530860a6e3f99dc10777c84bf22292c1 \ No newline at end of file +3d228334530860a6e3f99dc10777c84bf22292c1 +# Format markdown files with Prettier +dfe2eaaf20f0b679d94e5a799757c4394d80f1cc \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index 6cd73daf..05cdeec9 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -5,7 +5,5 @@ Before filing issues, please check the following points first: - [ ] Read the FAQ at https://github.com/handlebars-lang/handlebars.js/blob/master/FAQ.md - [ ] Use the jsfiddle-template at https://jsfiddle.net/4nbwjaqz/4/ to reproduce problems or bugs -This will probably help you to get a solution faster. +This will probably help you to get a solution faster. For bugs, it would be great to have a PR with a failing test-case. - - diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 7b0c5f17..c653c915 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -9,4 +9,4 @@ Generally we like to see pull requests that - [ ] Have tests - [ ] Have the [typings](https://www.typescriptlang.org/docs/handbook/declaration-files/introduction.html) (lib/handlebars.d.ts) updated on every API change. If you need help, updating those, please mention that in the PR description. - [ ] Don't significantly decrease the current code coverage (see coverage/lcov-report/index.html) -- [ ] Currently, the `4.x`-branch contains the latest version. Please target that branch in the PR. \ No newline at end of file +- [ ] Currently, the `4.x`-branch contains the latest version. Please target that branch in the PR. diff --git a/FAQ.md b/FAQ.md index 4edcb8ba..ddb26154 100644 --- a/FAQ.md +++ b/FAQ.md @@ -2,53 +2,53 @@ ## How can I file a bug report: - See our guidelines on [reporting issues](https://github.com/handlebars-lang/handlebars.js/blob/master/CONTRIBUTING.md#reporting-issues). +See our guidelines on [reporting issues](https://github.com/handlebars-lang/handlebars.js/blob/master/CONTRIBUTING.md#reporting-issues). ## Why isn't my Mustache template working? - Handlebars deviates from Mustache slightly on a few behaviors. These variations are documented in our [readme](https://github.com/handlebars-lang/handlebars.js#differences-between-handlebarsjs-and-mustache). +Handlebars deviates from Mustache slightly on a few behaviors. These variations are documented in our [readme](https://github.com/handlebars-lang/handlebars.js#differences-between-handlebarsjs-and-mustache). ## Why is it slower when compiling? - The Handlebars compiler must parse the template and construct a JavaScript program which can then be run. Under some environments such as older mobile devices this can have a performance impact which can be avoided by precompiling. Generally it's recommended that precompilation and the runtime library be used on all clients. +The Handlebars compiler must parse the template and construct a JavaScript program which can then be run. Under some environments such as older mobile devices this can have a performance impact which can be avoided by precompiling. Generally it's recommended that precompilation and the runtime library be used on all clients. ## Why doesn't this work with Content Security Policy restrictions? - When not using the precompiler, Handlebars generates a dynamic function for each template which can cause issues with pages that have enabled Content Policy. It's recommended that templates are precompiled or the `unsafe-eval` policy is enabled for sites that must generate dynamic templates at runtime. +When not using the precompiler, Handlebars generates a dynamic function for each template which can cause issues with pages that have enabled Content Policy. It's recommended that templates are precompiled or the `unsafe-eval` policy is enabled for sites that must generate dynamic templates at runtime. ## How can I include script tags in my template? - If loading the template via an inlined ` - ``` +```html + +``` - It's generally recommended that templates are served through external, precompiled, files, which do not suffer from this issue. +It's generally recommended that templates are served through external, precompiled, files, which do not suffer from this issue. ## Why are my precompiled scripts throwing exceptions? - When using the precompiler, it's important that a supporting version of the Handlebars runtime be loaded on the target page. In version 1.x there were rudimentary checks to compare the version but these did not always work. This is fixed under 2.x but the version checking does not work between these two versions. If you see unexpected errors such as `undefined is not a function` or similar, please verify that the same version is being used for both the precompiler and the client. This can be checked via: +When using the precompiler, it's important that a supporting version of the Handlebars runtime be loaded on the target page. In version 1.x there were rudimentary checks to compare the version but these did not always work. This is fixed under 2.x but the version checking does not work between these two versions. If you see unexpected errors such as `undefined is not a function` or similar, please verify that the same version is being used for both the precompiler and the client. This can be checked via: - ```sh - handlebars --version - ``` +```sh +handlebars --version +``` - If using the integrated precompiler and +If using the integrated precompiler and - ```javascript - console.log(Handlebars.VERSION); - ``` +```javascript +console.log(Handlebars.VERSION); +``` - On the client side. +On the client side. - We include the built client libraries in the npm package for those who want to be certain that they are using the same client libraries as the compiler. +We include the built client libraries in the npm package for those who want to be certain that they are using the same client libraries as the compiler. - Should these match, please file an issue with us, per our [issue filing guidelines](https://github.com/handlebars-lang/handlebars.js/blob/master/CONTRIBUTING.md#reporting-issues). +Should these match, please file an issue with us, per our [issue filing guidelines](https://github.com/handlebars-lang/handlebars.js/blob/master/CONTRIBUTING.md#reporting-issues). ## How do I load the runtime library when using AMD? - The `handlebars.runtime.js` file includes a UMD build, which exposes the library as both the module root and the `default` field for compatibility. +The `handlebars.runtime.js` file includes a UMD build, which exposes the library as both the module root and the `default` field for compatibility. diff --git a/SECURITY.md b/SECURITY.md index ef645e02..5ec5d795 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -5,7 +5,7 @@ We recommend always using the latest versions of Handlebars and its official com ## Supported Versions | Version | Supported | -|---------| ------------------ | +| ------- | ------------------ | | 5.0.x | :white_check_mark: | | 4.7.x | :white_check_mark: | | < 4.7 | :x: | diff --git a/components/component.json b/components/component.json index f74c8396..41bf71bd 100644 --- a/components/component.json +++ b/components/component.json @@ -3,7 +3,5 @@ "repo": "components/handlebars.js", "version": "1.0.0", "main": "handlebars.js", - "scripts": [ - "handlebars.js" - ] + "scripts": ["handlebars.js"] } diff --git a/components/composer.json b/components/composer.json index c5dc4271..7e9806b2 100644 --- a/components/composer.json +++ b/components/composer.json @@ -1,35 +1,35 @@ { - "name": "components/handlebars.js", - "description": "Handlebars.js and Mustache are both logicless templating languages that keep the view and the code separated like we all know they should be.", - "homepage": "http://handlebarsjs.com", - "license": "MIT", - "type": "component", - "keywords": [ - "handlebars", - "mustache", - "html" - ], - "authors": [ - { - "name": "Chris Wanstrath", - "homepage": "http://chriswanstrath.com" - } - ], - "require": { - "robloach/component-installer": "*" - }, - "extra": { - "component": { - "name": "handlebars", - "scripts": [ - "handlebars.js" - ], - "files": [ - "handlebars.runtime.js" - ], - "shim": { - "exports": "Handlebars" - } - } + "name": "components/handlebars.js", + "description": "Handlebars.js and Mustache are both logicless templating languages that keep the view and the code separated like we all know they should be.", + "homepage": "http://handlebarsjs.com", + "license": "MIT", + "type": "component", + "keywords": [ + "handlebars", + "mustache", + "html" + ], + "authors": [ + { + "name": "Chris Wanstrath", + "homepage": "http://chriswanstrath.com" } + ], + "require": { + "robloach/component-installer": "*" + }, + "extra": { + "component": { + "name": "handlebars", + "scripts": [ + "handlebars.js" + ], + "files": [ + "handlebars.runtime.js" + ], + "shim": { + "exports": "Handlebars" + } + } + } } diff --git a/docs/compiler-api.md b/docs/compiler-api.md index 01a1df5b..ff9c4b27 100644 --- a/docs/compiler-api.md +++ b/docs/compiler-api.md @@ -34,8 +34,8 @@ let ast = Handlebars.parseWithoutProcessing(myTemplate); `Handlebars.parse` will parse the template with `parseWithoutProcessing` (see above) then it will update the AST to strip extraneous whitespace. The whitespace stripping functionality handles two distinct situations: -* Removes whitespace around dynamic statements that are on a line by themselves (aka "stand alone") -* Applies "whitespace control" characters (i.e. `~`) by truncating the `ContentStatement` `value` property appropriately (e.g. `\n\n{{~foo}}` would have a `ContentStatement` with a `value` of `''`) +- Removes whitespace around dynamic statements that are on a line by themselves (aka "stand alone") +- Applies "whitespace control" characters (i.e. `~`) by truncating the `ContentStatement` `value` property appropriately (e.g. `\n\n{{~foo}}` would have a `ContentStatement` with a `value` of `''`) `Handlebars.parse` is used internally by `Handlebars.precompile` and `Handlebars.compile`. @@ -71,7 +71,7 @@ interface Position { interface Program <: Node { type: "Program"; body: [ Statement ]; - + blockParams: [ string ]; } ``` @@ -132,7 +132,6 @@ interface PartialBlockStatement <: Statement { `name` will be a `SubExpression` when tied to a dynamic partial, i.e. `{{> (foo) }}`, otherwise this is a path or literal whose `original` value is used to lookup the desired partial. - ```java interface ContentStatement <: Statement { type: "ContentStatement"; @@ -148,7 +147,6 @@ interface CommentStatement <: Statement { } ``` - ```java interface Decorator <: Statement { type: "Decorator"; @@ -209,7 +207,6 @@ interface PathExpression <: Expression { - `parts` is an array of the names in the path. `foo.bar` would be `['foo', 'bar']`. Scope references, `.`, `..`, and `this` should be omitted from this array. - `original` is the path as entered by the user. Separator and scope references are left untouched. - ##### Literals ```java @@ -242,7 +239,6 @@ interface NullLiteral <: Literal { } ``` - ### Miscellaneous ```java @@ -279,8 +275,8 @@ function ImportScanner() { } ImportScanner.prototype = new Visitor(); -ImportScanner.prototype.PartialStatement = function(partial) { - this.partials.push({request: partial.name.original}); +ImportScanner.prototype.PartialStatement = function (partial) { + this.partials.push({ request: partial.name.original }); Visitor.prototype.PartialStatement.call(this, partial); }; @@ -309,20 +305,20 @@ The `Handlebars.JavaScriptCompiler` object has a number of methods that may be c Note that this does not impact dynamic partials, which implementors need to be aware of. Overriding `VM.resolvePartial` may be required to support dynamic cases. - `depthedLookup(name)` - Used to generate code that resolves parameters within any context in the stack. Is only used in `compat` mode. + Used to generate code that resolves parameters within any context in the stack. Is only used in `compat` mode. - `compilerInfo()` Allows for custom compiler flags used in the runtime version checking logic. - `appendToBuffer(source, location, explicit)` - Allows for code buffer emitting code. Defaults behavior is string concatenation. + Allows for code buffer emitting code. Defaults behavior is string concatenation. - - `source` is the source code whose result is to be appending - - `location` is the location of the source in the source map. - - `explicit` is a flag signaling that the emit operation must occur, vs. the lazy evaled options otherwise. + - `source` is the source code whose result is to be appending + - `location` is the location of the source in the source map. + - `explicit` is a flag signaling that the emit operation must occur, vs. the lazy evaled options otherwise. - `initializeBuffer()` - Allows for buffers other than the default string buffer to be used. Generally needs to be paired with a custom `appendToBuffer` implementation. + Allows for buffers other than the default string buffer to be used. Generally needs to be paired with a custom `appendToBuffer` implementation. ### Example for the compiler api. @@ -330,7 +326,6 @@ This example changes all lookups of properties are performed by a helper (`looku There is also [a jsfiddle with this code](https://jsfiddle.net/9D88g/162/) if you want to play around with it. - ```javascript function MyCompiler() { Handlebars.JavaScriptCompiler.apply(this, arguments); @@ -338,29 +333,35 @@ function MyCompiler() { MyCompiler.prototype = new Handlebars.JavaScriptCompiler(); // Use this compile to compile BlockStatment-Blocks -MyCompiler.prototype.compiler = MyCompiler +MyCompiler.prototype.compiler = MyCompiler; -MyCompiler.prototype.nameLookup = function(parent, name, type) { +MyCompiler.prototype.nameLookup = function (parent, name, type) { if (type === 'context') { - return this.source.functionCall('helpers.lookupLowerCase', '', [parent, JSON.stringify(name)]) + return this.source.functionCall('helpers.lookupLowerCase', '', [ + parent, + JSON.stringify(name), + ]); } else { - return Handlebars.JavaScriptCompiler.prototype.nameLookup.call(this, parent, name, type); + return Handlebars.JavaScriptCompiler.prototype.nameLookup.call( + this, + parent, + name, + type + ); } -} +}; var env = Handlebars.create(); -env.registerHelper('lookupLowerCase', function(parent, name) { - return parent[name.toLowerCase()] -}) +env.registerHelper('lookupLowerCase', function (parent, name) { + return parent[name.toLowerCase()]; +}); env.JavaScriptCompiler = MyCompiler; var template = env.compile('{{#each Test}} ({{Value}}) {{/each}}'); -console.log(template({ - test: [ - {value: 'a'}, - {value: 'b'}, - {value: 'c'} - ] -})); +console.log( + template({ + test: [{ value: 'a' }, { value: 'b' }, { value: 'c' }], + }) +); ``` diff --git a/package-lock.json b/package-lock.json index 52b688df..3a3b6f9a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -30,7 +30,7 @@ "dirty-chai": "^2.0.1", "dustjs-linkedin": "^2.0.2", "eslint": "^8.25.0", - "eslint-config-prettier": "^8.5.0", + "eslint-config-prettier": "^8.9.0", "eslint-plugin-compat": "4.0", "fs-extra": "^8.1.0", "grunt": "^1.0.4", @@ -51,7 +51,7 @@ "mock-stdin": "^0.3.0", "mustache": "^2.1.3", "nyc": "^14.1.1", - "prettier": "^2.7.1", + "prettier": "^3.0.0", "semver": "^5.0.1", "sinon": "^7.5.0", "typescript": "^3.4.3", @@ -4094,9 +4094,9 @@ } }, "node_modules/eslint-config-prettier": { - "version": "8.5.0", - "resolved": "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-8.5.0.tgz", - "integrity": "sha512-obmWKLUNCnhtQRKc+tmnYuQl0pFU1ibYJQ5BGhTVB08bHe9wC8qUeG7c08dj9XX+AuPj1YSGSQIHl1pnDHZR0Q==", + "version": "8.9.0", + "resolved": "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-8.9.0.tgz", + "integrity": "sha512-+sbni7NfVXnOpnRadUA8S28AUlsZt9GjgFvABIRL9Hkn8KqNzOp+7Lw4QWtrwn20KzU3wqu1QoOj2m+7rKRqkA==", "dev": true, "bin": { "eslint-config-prettier": "bin/cli.js" @@ -11285,15 +11285,15 @@ } }, "node_modules/prettier": { - "version": "2.7.1", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.7.1.tgz", - "integrity": "sha512-ujppO+MkdPqoVINuDFDRLClm7D78qbDt0/NR+wp5FqEZOoTNAjPHWj17QRhu7geIHJfcNhRk1XVQmF8Bp3ye+g==", + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.0.0.tgz", + "integrity": "sha512-zBf5eHpwHOGPC47h0zrPyNn+eAEIdEzfywMoYn2XPi0P44Zp0tSq64rq0xAREh4auw2cJZHo9QUob+NqCQky4g==", "dev": true, "bin": { - "prettier": "bin-prettier.js" + "prettier": "bin/prettier.cjs" }, "engines": { - "node": ">=10.13.0" + "node": ">=14" }, "funding": { "url": "https://github.com/prettier/prettier?sponsor=1" @@ -18140,9 +18140,9 @@ } }, "eslint-config-prettier": { - "version": "8.5.0", - "resolved": "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-8.5.0.tgz", - "integrity": "sha512-obmWKLUNCnhtQRKc+tmnYuQl0pFU1ibYJQ5BGhTVB08bHe9wC8qUeG7c08dj9XX+AuPj1YSGSQIHl1pnDHZR0Q==", + "version": "8.9.0", + "resolved": "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-8.9.0.tgz", + "integrity": "sha512-+sbni7NfVXnOpnRadUA8S28AUlsZt9GjgFvABIRL9Hkn8KqNzOp+7Lw4QWtrwn20KzU3wqu1QoOj2m+7rKRqkA==", "dev": true, "requires": {} }, @@ -23659,9 +23659,9 @@ "dev": true }, "prettier": { - "version": "2.7.1", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.7.1.tgz", - "integrity": "sha512-ujppO+MkdPqoVINuDFDRLClm7D78qbDt0/NR+wp5FqEZOoTNAjPHWj17QRhu7geIHJfcNhRk1XVQmF8Bp3ye+g==", + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.0.0.tgz", + "integrity": "sha512-zBf5eHpwHOGPC47h0zrPyNn+eAEIdEzfywMoYn2XPi0P44Zp0tSq64rq0xAREh4auw2cJZHo9QUob+NqCQky4g==", "dev": true }, "pretty-bytes": { diff --git a/package.json b/package.json index ede7920c..7298cd0e 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "dirty-chai": "^2.0.1", "dustjs-linkedin": "^2.0.2", "eslint": "^8.25.0", - "eslint-config-prettier": "^8.5.0", + "eslint-config-prettier": "^8.9.0", "eslint-plugin-compat": "4.0", "fs-extra": "^8.1.0", "grunt": "^1.0.4", @@ -62,7 +62,7 @@ "mock-stdin": "^0.3.0", "mustache": "^2.1.3", "nyc": "^14.1.1", - "prettier": "^2.7.1", + "prettier": "^3.0.0", "semver": "^5.0.1", "sinon": "^7.5.0", "typescript": "^3.4.3", @@ -81,7 +81,7 @@ "build": "grunt build", "release": "grunt release", "publish:aws": "npm run test:tasks && grunt && grunt publish-to-aws", - "format": "prettier --write '**/*.js' && eslint --fix .", + "format": "prettier --write '**/*.{js,css,json,md}' && eslint --fix .", "lint": "npm run lint:eslint && npm run lint:prettier && npm run lint:types", "lint:eslint": "eslint --max-warnings 0 .", "lint:prettier": "prettier --check '**/*.js'", @@ -127,7 +127,7 @@ } }, "lint-staged": { - "*.{js,css,json}": [ + "*.{js,css,json,md}": [ "prettier --write", "git add" ], diff --git a/prettier.config.js b/prettier.config.js index 70767b70..257e164f 100644 --- a/prettier.config.js +++ b/prettier.config.js @@ -2,4 +2,5 @@ module.exports = { tabWidth: 2, semi: true, singleQuote: true, + trailingComma: 'es5', }; diff --git a/tests/browser/README.md b/tests/browser/README.md index b35a5a2b..74d3d3c7 100644 --- a/tests/browser/README.md +++ b/tests/browser/README.md @@ -11,4 +11,4 @@ npm install npx grunt prepare docker pull mcr.microsoft.com/playwright:focal docker run -it --rm --volume $(pwd):/srv/app --workdir /srv/app --ipc=host mcr.microsoft.com/playwright:focal npm run test:browser -``` \ No newline at end of file +```