Skip to content
Permalink
Browse files

Merge branch '4.x'

# Conflicts:
#	components/bower.json
#	components/handlebars.js.nuspec
#	components/package.json
#	package-lock.json
#	package.json
  • Loading branch information
nknapp committed Nov 9, 2019
2 parents e46c239 + 7ef8617 commit b0bb2a42b455d260b882bb5f0f13fee0357990cb
Showing with 368 additions and 30 deletions.
  1. +6 −18 .eslintrc.js
  2. +28 −0 docs/compiler-api.md
  3. +2 −1 lib/handlebars.js
  4. +1 −1 lib/handlebars/base.js
  5. +10 −2 lib/handlebars/compiler/base.js
  6. +111 −0 package-lock.json
  7. +2 −0 package.json
  8. +30 −1 release-notes.md
  9. +7 −2 spec/.eslintrc
  10. +105 −0 spec/ast.js
  11. +1 −1 spec/env/browser.js
  12. +17 −3 types/index.d.ts
  13. +48 −1 types/test.ts
@@ -1,25 +1,11 @@
module.exports = {
"extends": "eslint:recommended",
"extends": ["eslint:recommended","plugin:compat/recommended"],
"globals": {
"self": false
},
"env": {
"node": true
},
"ecmaFeatures": {
// Enabling features that can be implemented without polyfills. Want to avoid polyfills at this time.
"arrowFunctions": true,
"blockBindings": true,
"defaultParams": true,
"destructuring": true,
"modules": true,
"objectLiteralComputedProperties": true,
"objectLiteralDuplicateProperties": true,
"objectLiteralShorthandMethods": true,
"objectLiteralShorthandProperties": true,
"restParams": true,
"spread": true,
"templateStrings": true
"node": true,
"es6": true
},
"rules": {
// overrides eslint:recommended defaults
@@ -124,6 +110,8 @@ module.exports = {
"no-var": "warn"
},
"parserOptions": {
"sourceType": "module"
"sourceType": "module",
"ecmaVersion": 6,
"ecmaFeatures": {}
}
}
@@ -16,6 +16,34 @@ var ast = Handlebars.parse(myTemplate);
Handlebars.precompile(ast);
```

### Parsing

There are two primary APIs that are used to parse an existing template into the AST:

#### parseWithoutProcessing

`Handlebars.parseWithoutProcessing` is the primary mechanism to turn a raw template string into the Handlebars AST described in this document. No processing is done on the resulting AST which makes this ideal for codemod (for source to source transformation) tooling.

Example:

```js
let ast = Handlebars.parseWithoutProcessing(myTemplate);
```

#### parse

`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 `''`)

`Handlebars.parse` is used internally by `Handlebars.precompile` and `Handlebars.compile`.

Example:

```js
let ast = Handlebars.parse(myTemplate);
```

### Basic

@@ -2,7 +2,7 @@ import runtime from './handlebars.runtime';

// Compiler imports
import AST from './handlebars/compiler/ast';
import { parser as Parser, parse } from './handlebars/compiler/base';
import { parser as Parser, parse, parseWithoutProcessing } from './handlebars/compiler/base';
import { Compiler, compile, precompile } from './handlebars/compiler/compiler';
import JavaScriptCompiler from './handlebars/compiler/javascript-compiler';
import Visitor from './handlebars/compiler/visitor';
@@ -25,6 +25,7 @@ function create() {
hb.JavaScriptCompiler = JavaScriptCompiler;
hb.Parser = Parser;
hb.parse = parse;
hb.parseWithoutProcessing = parseWithoutProcessing;

return hb;
}
@@ -4,7 +4,7 @@ import {registerDefaultHelpers} from './helpers';
import {registerDefaultDecorators} from './decorators';
import logger from './logger';

export const VERSION = '4.4.5';
export const VERSION = '4.5.1';
export const COMPILER_REVISION = 8;
export const LAST_COMPATIBLE_COMPILER_REVISION = 7;

@@ -8,7 +8,7 @@ export { parser };
let yy = {};
extend(yy, Helpers);

export function parse(input, options) {
export function parseWithoutProcessing(input, options) {
// Just return if an already-compiled AST was passed in.
if (input.type === 'Program') { return input; }

@@ -19,6 +19,14 @@ export function parse(input, options) {
return new yy.SourceLocation(options && options.srcName, locInfo);
};

let ast = parser.parse(input);

return ast;
}

export function parse(input, options) {
let ast = parseWithoutProcessing(input, options);
let strip = new WhitespaceControl(options);
return strip.accept(parser.parse(input));

return strip.accept(ast);
}

Some generated files are not rendered by default. Learn more.

@@ -37,6 +37,8 @@
"dtslint": "^0.5.5",
"dustjs-linkedin": "^2.0.2",
"eco": "~1.1.0-rc-3",
"eslint-plugin-compat": "^3.3.0",
"eslint-plugin-es5": "^1.4.1",
"grunt": "^1.0.3",
"grunt-babel": "^5.0.0",
"grunt-bg-shell": "^2.3.3",
@@ -2,7 +2,36 @@

## Development

[Commits](https://github.com/wycats/handlebars.js/compare/v4.4.5...master)
[Commits](https://github.com/wycats/handlebars.js/compare/v4.5.1...master)

## v4.5.1 - October 29th, 2019
Bugfixs

- fix: move "eslint-plugin-compat" to devDependencies - 5e9d17f (#1589)

Compatibility notes:
- No compatibility issues are to be expected


[Commits](https://github.com/wycats/handlebars.js/compare/v4.5.0...v4.5.1)

## v4.5.0 - October 28th, 2019
Features / Improvements
- Add method Handlebars.parseWithoutProcessing (#1584) - 62ed3c2
- add guard to if & unless helpers (#1549)
- show source location for the strict lookup exceptions - feb60f8

Bugfixes:
- Use objects for hash value tracking - 7fcf9d2

Chore:
- Resolve deprecation warning message from eslint while running eslint (#1586) - 7052e88
- chore: add eslint-plugin-compat and eslint-plugin-es5 - 088e618

Compatibility notes:
- No compatibility issues are to be expected

[Commits](https://github.com/wycats/handlebars.js/compare/v4.4.5...v4.5.0)

## v4.4.5 - October 20th, 2019
Bugfixes:
@@ -1,14 +1,19 @@
{
"extends": [
"../.eslintrc.js",
"plugin:es5/no-es2015"
],
"plugins": [
"es5"
],
"globals": {
"CompilerContext": true,
"Handlebars": true,
"handlebarsEnv": true,

"shouldCompileTo": true,
"shouldCompileToWithPartials": true,
"shouldThrow": true,
"compileWithPartials": true,

"console": true,
"require": true,
"suite": true,

0 comments on commit b0bb2a4

Please sign in to comment.
You can’t perform that action at this time.