handlebars-jaylinski 4.7.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. package/LICENSE +19 -0
  2. package/README.markdown +169 -0
  3. package/bin/.eslintrc.js +6 -0
  4. package/bin/handlebars +176 -0
  5. package/dist/amd/handlebars/base.js +106 -0
  6. package/dist/amd/handlebars/compiler/ast.js +31 -0
  7. package/dist/amd/handlebars/compiler/base.js +45 -0
  8. package/dist/amd/handlebars/compiler/code-gen.js +165 -0
  9. package/dist/amd/handlebars/compiler/compiler.js +562 -0
  10. package/dist/amd/handlebars/compiler/helpers.js +228 -0
  11. package/dist/amd/handlebars/compiler/javascript-compiler.js +1150 -0
  12. package/dist/amd/handlebars/compiler/parser.js +737 -0
  13. package/dist/amd/handlebars/compiler/printer.js +186 -0
  14. package/dist/amd/handlebars/compiler/visitor.js +138 -0
  15. package/dist/amd/handlebars/compiler/whitespace-control.js +219 -0
  16. package/dist/amd/handlebars/decorators/inline.js +25 -0
  17. package/dist/amd/handlebars/decorators.js +16 -0
  18. package/dist/amd/handlebars/exception.js +64 -0
  19. package/dist/amd/handlebars/helpers/block-helper-missing.js +35 -0
  20. package/dist/amd/handlebars/helpers/each.js +99 -0
  21. package/dist/amd/handlebars/helpers/helper-missing.js +22 -0
  22. package/dist/amd/handlebars/helpers/if.js +41 -0
  23. package/dist/amd/handlebars/helpers/log.js +24 -0
  24. package/dist/amd/handlebars/helpers/lookup.js +14 -0
  25. package/dist/amd/handlebars/helpers/with.js +38 -0
  26. package/dist/amd/handlebars/helpers.js +44 -0
  27. package/dist/amd/handlebars/internal/create-new-lookup-object.js +22 -0
  28. package/dist/amd/handlebars/internal/proto-access.js +71 -0
  29. package/dist/amd/handlebars/internal/wrapHelper.js +21 -0
  30. package/dist/amd/handlebars/logger.js +44 -0
  31. package/dist/amd/handlebars/no-conflict.js +28 -0
  32. package/dist/amd/handlebars/runtime.js +356 -0
  33. package/dist/amd/handlebars/safe-string.js +15 -0
  34. package/dist/amd/handlebars/utils.js +126 -0
  35. package/dist/amd/handlebars.js +52 -0
  36. package/dist/amd/handlebars.runtime.js +44 -0
  37. package/dist/amd/precompiler.js +314 -0
  38. package/dist/cjs/handlebars/base.js +116 -0
  39. package/dist/cjs/handlebars/compiler/ast.js +31 -0
  40. package/dist/cjs/handlebars/compiler/base.js +57 -0
  41. package/dist/cjs/handlebars/compiler/code-gen.js +168 -0
  42. package/dist/cjs/handlebars/compiler/compiler.js +566 -0
  43. package/dist/cjs/handlebars/compiler/helpers.js +228 -0
  44. package/dist/cjs/handlebars/compiler/javascript-compiler.js +1158 -0
  45. package/dist/cjs/handlebars/compiler/parser.js +737 -0
  46. package/dist/cjs/handlebars/compiler/printer.js +186 -0
  47. package/dist/cjs/handlebars/compiler/visitor.js +140 -0
  48. package/dist/cjs/handlebars/compiler/whitespace-control.js +221 -0
  49. package/dist/cjs/handlebars/decorators/inline.js +29 -0
  50. package/dist/cjs/handlebars/decorators.js +16 -0
  51. package/dist/cjs/handlebars/exception.js +64 -0
  52. package/dist/cjs/handlebars/helpers/block-helper-missing.js +39 -0
  53. package/dist/cjs/handlebars/helpers/each.js +104 -0
  54. package/dist/cjs/handlebars/helpers/helper-missing.js +25 -0
  55. package/dist/cjs/handlebars/helpers/if.js +46 -0
  56. package/dist/cjs/handlebars/helpers/log.js +26 -0
  57. package/dist/cjs/handlebars/helpers/lookup.js +16 -0
  58. package/dist/cjs/handlebars/helpers/with.js +43 -0
  59. package/dist/cjs/handlebars/helpers.js +56 -0
  60. package/dist/cjs/handlebars/internal/create-new-lookup-object.js +22 -0
  61. package/dist/cjs/handlebars/internal/proto-access.js +73 -0
  62. package/dist/cjs/handlebars/internal/wrapHelper.js +19 -0
  63. package/dist/cjs/handlebars/logger.js +47 -0
  64. package/dist/cjs/handlebars/no-conflict.js +30 -0
  65. package/dist/cjs/handlebars/runtime.js +372 -0
  66. package/dist/cjs/handlebars/safe-string.js +15 -0
  67. package/dist/cjs/handlebars/utils.js +124 -0
  68. package/dist/cjs/handlebars.js +66 -0
  69. package/dist/cjs/handlebars.runtime.js +66 -0
  70. package/dist/cjs/precompiler.js +328 -0
  71. package/dist/handlebars.amd.js +4639 -0
  72. package/dist/handlebars.amd.min.js +29 -0
  73. package/dist/handlebars.js +5972 -0
  74. package/dist/handlebars.min.js +29 -0
  75. package/dist/handlebars.runtime.amd.js +1302 -0
  76. package/dist/handlebars.runtime.amd.min.js +27 -0
  77. package/dist/handlebars.runtime.js +2563 -0
  78. package/dist/handlebars.runtime.min.js +27 -0
  79. package/lib/.eslintrc.js +8 -0
  80. package/lib/handlebars/base.js +94 -0
  81. package/lib/handlebars/compiler/ast.js +32 -0
  82. package/lib/handlebars/compiler/base.js +34 -0
  83. package/lib/handlebars/compiler/code-gen.js +171 -0
  84. package/lib/handlebars/compiler/compiler.js +594 -0
  85. package/lib/handlebars/compiler/helpers.js +219 -0
  86. package/lib/handlebars/compiler/javascript-compiler.js +1293 -0
  87. package/lib/handlebars/compiler/parser.js +622 -0
  88. package/lib/handlebars/compiler/printer.js +178 -0
  89. package/lib/handlebars/compiler/visitor.js +136 -0
  90. package/lib/handlebars/compiler/whitespace-control.js +234 -0
  91. package/lib/handlebars/decorators/inline.js +22 -0
  92. package/lib/handlebars/decorators.js +5 -0
  93. package/lib/handlebars/exception.js +68 -0
  94. package/lib/handlebars/helpers/block-helper-missing.js +35 -0
  95. package/lib/handlebars/helpers/each.js +101 -0
  96. package/lib/handlebars/helpers/helper-missing.js +15 -0
  97. package/lib/handlebars/helpers/if.js +33 -0
  98. package/lib/handlebars/helpers/log.js +19 -0
  99. package/lib/handlebars/helpers/lookup.js +9 -0
  100. package/lib/handlebars/helpers/with.js +39 -0
  101. package/lib/handlebars/helpers.js +26 -0
  102. package/lib/handlebars/internal/create-new-lookup-object.js +11 -0
  103. package/lib/handlebars/internal/proto-access.js +70 -0
  104. package/lib/handlebars/internal/wrapHelper.js +13 -0
  105. package/lib/handlebars/logger.js +39 -0
  106. package/lib/handlebars/no-conflict.js +23 -0
  107. package/lib/handlebars/runtime.js +450 -0
  108. package/lib/handlebars/safe-string.js +10 -0
  109. package/lib/handlebars/utils.js +116 -0
  110. package/lib/handlebars.js +46 -0
  111. package/lib/handlebars.runtime.js +37 -0
  112. package/lib/index.js +26 -0
  113. package/lib/precompiler.js +341 -0
  114. package/package.json +135 -0
  115. package/release-notes.md +1101 -0
  116. package/runtime.d.ts +5 -0
  117. package/runtime.js +3 -0
  118. package/types/index.d.ts +422 -0
@@ -0,0 +1,341 @@
1
+ /* eslint-env node */
2
+ /* eslint-disable no-console */
3
+ import Async from 'neo-async';
4
+ import fs from 'fs';
5
+ import * as Handlebars from './handlebars';
6
+ import { basename } from 'path';
7
+ import { SourceMapConsumer, SourceNode } from 'source-map';
8
+
9
+ module.exports.loadTemplates = function(opts, callback) {
10
+ loadStrings(opts, function(err, strings) {
11
+ if (err) {
12
+ callback(err);
13
+ } else {
14
+ loadFiles(opts, function(err, files) {
15
+ if (err) {
16
+ callback(err);
17
+ } else {
18
+ opts.templates = strings.concat(files);
19
+ callback(undefined, opts);
20
+ }
21
+ });
22
+ }
23
+ });
24
+ };
25
+
26
+ function loadStrings(opts, callback) {
27
+ let strings = arrayCast(opts.string),
28
+ names = arrayCast(opts.name);
29
+
30
+ if (names.length !== strings.length && strings.length > 1) {
31
+ return callback(
32
+ new Handlebars.Exception(
33
+ 'Number of names did not match the number of string inputs'
34
+ )
35
+ );
36
+ }
37
+
38
+ Async.map(
39
+ strings,
40
+ function(string, callback) {
41
+ if (string !== '-') {
42
+ callback(undefined, string);
43
+ } else {
44
+ // Load from stdin
45
+ let buffer = '';
46
+ process.stdin.setEncoding('utf8');
47
+
48
+ process.stdin.on('data', function(chunk) {
49
+ buffer += chunk;
50
+ });
51
+ process.stdin.on('end', function() {
52
+ callback(undefined, buffer);
53
+ });
54
+ }
55
+ },
56
+ function(err, strings) {
57
+ strings = strings.map((string, index) => ({
58
+ name: names[index],
59
+ path: names[index],
60
+ source: string
61
+ }));
62
+ callback(err, strings);
63
+ }
64
+ );
65
+ }
66
+
67
+ function loadFiles(opts, callback) {
68
+ // Build file extension pattern
69
+ let extension = (opts.extension || 'handlebars').replace(
70
+ /[\\^$*+?.():=!|{}\-[\]]/g,
71
+ function(arg) {
72
+ return '\\' + arg;
73
+ }
74
+ );
75
+ extension = new RegExp('\\.' + extension + '$');
76
+
77
+ let ret = [],
78
+ queue = (opts.files || []).map(template => ({ template, root: opts.root }));
79
+ Async.whilst(
80
+ () => queue.length,
81
+ function(callback) {
82
+ let { template: path, root } = queue.shift();
83
+
84
+ fs.stat(path, function(err, stat) {
85
+ if (err) {
86
+ return callback(
87
+ new Handlebars.Exception(`Unable to open template file "${path}"`)
88
+ );
89
+ }
90
+
91
+ if (stat.isDirectory()) {
92
+ opts.hasDirectory = true;
93
+
94
+ fs.readdir(path, function(err, children) {
95
+ /* istanbul ignore next : Race condition that being too lazy to test */
96
+ if (err) {
97
+ return callback(err);
98
+ }
99
+ children.forEach(function(file) {
100
+ let childPath = path + '/' + file;
101
+
102
+ if (
103
+ extension.test(childPath) ||
104
+ fs.statSync(childPath).isDirectory()
105
+ ) {
106
+ queue.push({ template: childPath, root: root || path });
107
+ }
108
+ });
109
+
110
+ callback();
111
+ });
112
+ } else {
113
+ fs.readFile(path, 'utf8', function(err, data) {
114
+ /* istanbul ignore next : Race condition that being too lazy to test */
115
+ if (err) {
116
+ return callback(err);
117
+ }
118
+
119
+ if (opts.bom && data.indexOf('\uFEFF') === 0) {
120
+ data = data.substring(1);
121
+ }
122
+
123
+ // Clean the template name
124
+ let name = path;
125
+ if (!root) {
126
+ name = basename(name);
127
+ } else if (name.indexOf(root) === 0) {
128
+ name = name.substring(root.length + 1);
129
+ }
130
+ name = name.replace(extension, '');
131
+
132
+ ret.push({
133
+ path: path,
134
+ name: name,
135
+ source: data
136
+ });
137
+
138
+ callback();
139
+ });
140
+ }
141
+ });
142
+ },
143
+ function(err) {
144
+ if (err) {
145
+ callback(err);
146
+ } else {
147
+ callback(undefined, ret);
148
+ }
149
+ }
150
+ );
151
+ }
152
+
153
+ module.exports.cli = function(opts) {
154
+ if (opts.version) {
155
+ console.log(Handlebars.VERSION);
156
+ return;
157
+ }
158
+
159
+ if (!opts.templates.length && !opts.hasDirectory) {
160
+ throw new Handlebars.Exception(
161
+ 'Must define at least one template or directory.'
162
+ );
163
+ }
164
+
165
+ if (opts.simple && opts.min) {
166
+ throw new Handlebars.Exception('Unable to minimize simple output');
167
+ }
168
+
169
+ const multiple = opts.templates.length !== 1 || opts.hasDirectory;
170
+ if (opts.simple && multiple) {
171
+ throw new Handlebars.Exception(
172
+ 'Unable to output multiple templates in simple mode'
173
+ );
174
+ }
175
+
176
+ // Force simple mode if we have only one template and it's unnamed.
177
+ if (
178
+ !opts.amd &&
179
+ !opts.commonjs &&
180
+ opts.templates.length === 1 &&
181
+ !opts.templates[0].name
182
+ ) {
183
+ opts.simple = true;
184
+ }
185
+
186
+ // Convert the known list into a hash
187
+ let known = {};
188
+ if (opts.known && !Array.isArray(opts.known)) {
189
+ opts.known = [opts.known];
190
+ }
191
+ if (opts.known) {
192
+ for (let i = 0, len = opts.known.length; i < len; i++) {
193
+ known[opts.known[i]] = true;
194
+ }
195
+ }
196
+
197
+ const objectName = opts.partial ? 'Handlebars.partials' : 'templates';
198
+
199
+ let output = new SourceNode();
200
+ if (!opts.simple) {
201
+ if (opts.amd) {
202
+ output.add(
203
+ "define(['" +
204
+ opts.handlebarPath +
205
+ 'handlebars.runtime\'], function(Handlebars) {\n Handlebars = Handlebars["default"];'
206
+ );
207
+ } else if (opts.commonjs) {
208
+ output.add('var Handlebars = require("' + opts.commonjs + '");');
209
+ } else {
210
+ output.add('(function() {\n');
211
+ }
212
+ output.add(' var template = Handlebars.template, templates = ');
213
+ if (opts.namespace) {
214
+ output.add(opts.namespace);
215
+ output.add(' = ');
216
+ output.add(opts.namespace);
217
+ output.add(' || ');
218
+ }
219
+ output.add('{};\n');
220
+ }
221
+
222
+ opts.templates.forEach(function(template) {
223
+ let options = {
224
+ knownHelpers: known,
225
+ knownHelpersOnly: opts.o
226
+ };
227
+
228
+ if (opts.map) {
229
+ options.srcName = template.path;
230
+ }
231
+ if (opts.data) {
232
+ options.data = true;
233
+ }
234
+
235
+ let precompiled = Handlebars.precompile(template.source, options);
236
+
237
+ // If we are generating a source map, we have to reconstruct the SourceNode object
238
+ if (opts.map) {
239
+ let consumer = new SourceMapConsumer(precompiled.map);
240
+ precompiled = SourceNode.fromStringWithSourceMap(
241
+ precompiled.code,
242
+ consumer
243
+ );
244
+ }
245
+
246
+ if (opts.simple) {
247
+ output.add([precompiled, '\n']);
248
+ } else {
249
+ if (!template.name) {
250
+ throw new Handlebars.Exception('Name missing for template');
251
+ }
252
+
253
+ if (opts.amd && !multiple) {
254
+ output.add('return ');
255
+ }
256
+ output.add([
257
+ objectName,
258
+ "['",
259
+ template.name,
260
+ "'] = template(",
261
+ precompiled,
262
+ ');\n'
263
+ ]);
264
+ }
265
+ });
266
+
267
+ // Output the content
268
+ if (!opts.simple) {
269
+ if (opts.amd) {
270
+ if (multiple) {
271
+ output.add(['return ', objectName, ';\n']);
272
+ }
273
+ output.add('});');
274
+ } else if (!opts.commonjs) {
275
+ output.add('})();');
276
+ }
277
+ }
278
+
279
+ if (opts.map) {
280
+ output.add('\n//# sourceMappingURL=' + opts.map + '\n');
281
+ }
282
+
283
+ output = output.toStringWithSourceMap();
284
+ output.map = output.map + '';
285
+
286
+ if (opts.min) {
287
+ output = minify(output, opts.map);
288
+ }
289
+
290
+ if (opts.map) {
291
+ fs.writeFileSync(opts.map, output.map, 'utf8');
292
+ }
293
+ output = output.code;
294
+
295
+ if (opts.output) {
296
+ fs.writeFileSync(opts.output, output, 'utf8');
297
+ } else {
298
+ console.log(output);
299
+ }
300
+ };
301
+
302
+ function arrayCast(value) {
303
+ value = value != null ? value : [];
304
+ if (!Array.isArray(value)) {
305
+ value = [value];
306
+ }
307
+ return value;
308
+ }
309
+
310
+ /**
311
+ * Run uglify to minify the compiled template, if uglify exists in the dependencies.
312
+ *
313
+ * We are using `require` instead of `import` here, because es6-modules do not allow
314
+ * dynamic imports and uglify-js is an optional dependency. Since we are inside NodeJS here, this
315
+ * should not be a problem.
316
+ *
317
+ * @param {string} output the compiled template
318
+ * @param {string} sourceMapFile the file to write the source map to.
319
+ */
320
+ function minify(output, sourceMapFile) {
321
+ try {
322
+ // Try to resolve uglify-js in order to see if it does exist
323
+ require.resolve('uglify-js');
324
+ } catch (e) {
325
+ if (e.code !== 'MODULE_NOT_FOUND') {
326
+ // Something else seems to be wrong
327
+ throw e;
328
+ }
329
+ // it does not exist!
330
+ console.error(
331
+ 'Code minimization is disabled due to missing uglify-js dependency'
332
+ );
333
+ return output;
334
+ }
335
+ return require('uglify-js').minify(output.code, {
336
+ sourceMap: {
337
+ content: output.map,
338
+ url: sourceMapFile
339
+ }
340
+ });
341
+ }
package/package.json ADDED
@@ -0,0 +1,135 @@
1
+ {
2
+ "name": "handlebars-jaylinski",
3
+ "barename": "handlebars",
4
+ "version": "4.7.8",
5
+ "description": "Handlebars provides the power necessary to let you build semantic templates effectively with no frustration",
6
+ "homepage": "https://www.handlebarsjs.com/",
7
+ "keywords": [
8
+ "handlebars",
9
+ "mustache",
10
+ "template",
11
+ "html"
12
+ ],
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "https://github.com/handlebars-lang/handlebars.js.git"
16
+ },
17
+ "author": "Yehuda Katz",
18
+ "license": "MIT",
19
+ "readmeFilename": "README.md",
20
+ "engines": {
21
+ "node": ">=0.4.7"
22
+ },
23
+ "dependencies": {
24
+ "minimist": "^1.2.5",
25
+ "neo-async": "^2.6.2",
26
+ "source-map": "^0.6.1",
27
+ "wordwrap": "^1.0.0"
28
+ },
29
+ "optionalDependencies": {
30
+ "uglify-js": "^3.1.4"
31
+ },
32
+ "devDependencies": {
33
+ "@playwright/test": "^1.17.1",
34
+ "aws-sdk": "^2.1.49",
35
+ "babel-loader": "^5.0.0",
36
+ "babel-runtime": "^5.1.10",
37
+ "benchmark": "~1.0",
38
+ "chai": "^4.2.0",
39
+ "chai-diff": "^1.0.1",
40
+ "concurrently": "^5.0.0",
41
+ "dirty-chai": "^2.0.1",
42
+ "dtslint": "^0.5.5",
43
+ "dustjs-linkedin": "^2.0.2",
44
+ "eco": "~1.1.0-rc-3",
45
+ "eslint": "^6.7.2",
46
+ "eslint-config-prettier": "^6.7.0",
47
+ "eslint-plugin-compat": "^3.13.0",
48
+ "eslint-plugin-es5": "^1.4.1",
49
+ "fs-extra": "^8.1.0",
50
+ "grunt": "^1.0.4",
51
+ "grunt-babel": "^5.0.0",
52
+ "grunt-cli": "^1",
53
+ "grunt-contrib-clean": "^1",
54
+ "grunt-contrib-concat": "^1",
55
+ "grunt-contrib-connect": "^1",
56
+ "grunt-contrib-copy": "^1",
57
+ "grunt-contrib-requirejs": "^1",
58
+ "grunt-contrib-uglify": "^1",
59
+ "grunt-contrib-watch": "^1.1.0",
60
+ "grunt-shell": "^4.0.0",
61
+ "grunt-webpack": "^1.0.8",
62
+ "husky": "^3.1.0",
63
+ "jison": "~0.3.0",
64
+ "lint-staged": "^9.5.0",
65
+ "mocha": "^5",
66
+ "mock-stdin": "^0.3.0",
67
+ "mustache": "^2.1.3",
68
+ "nyc": "^14.1.1",
69
+ "prettier": "^1.19.1",
70
+ "semver": "^5.0.1",
71
+ "sinon": "^7.5.0",
72
+ "typescript": "^3.4.3",
73
+ "underscore": "^1.5.1",
74
+ "webpack": "^1.12.6",
75
+ "webpack-dev-server": "^1.12.1"
76
+ },
77
+ "main": "lib/index.js",
78
+ "types": "types/index.d.ts",
79
+ "browser": "./dist/cjs/handlebars.js",
80
+ "bin": {
81
+ "handlebars": "bin/handlebars"
82
+ },
83
+ "scripts": {
84
+ "build": "grunt build",
85
+ "release": "npm run build && grunt release",
86
+ "format": "prettier --write '**/*.js' && eslint --fix .",
87
+ "lint": "npm run lint:eslint && npm run lint:prettier && npm run lint:types",
88
+ "lint:eslint": "eslint --max-warnings 0 .",
89
+ "lint:prettier": "prettier --check '**/*.js'",
90
+ "lint:types": "dtslint types",
91
+ "test": "npm run test:mocha",
92
+ "test:mocha": "grunt build && grunt test",
93
+ "test:browser": "playwright test --config tests/browser/playwright.config.js tests/browser/spec.js",
94
+ "test:integration": "grunt integration-tests",
95
+ "test:serve": "grunt connect:server:keepalive",
96
+ "extensive-tests-and-publish-to-aws": "npx mocha tasks/tests/ && grunt --stack extensive-tests-and-publish-to-aws",
97
+ "--- combined tasks ---": "",
98
+ "check-before-pull-request": "concurrently --kill-others-on-fail npm:lint npm:test"
99
+ },
100
+ "jspm": {
101
+ "main": "handlebars",
102
+ "directories": {
103
+ "lib": "dist/amd"
104
+ },
105
+ "buildConfig": {
106
+ "minify": true
107
+ }
108
+ },
109
+ "files": [
110
+ "bin",
111
+ "dist/*.js",
112
+ "dist/amd/**/*.js",
113
+ "dist/cjs/**/*.js",
114
+ "lib",
115
+ "release-notes.md",
116
+ "runtime.js",
117
+ "types/*.d.ts",
118
+ "runtime.d.ts"
119
+ ],
120
+ "husky": {
121
+ "hooks": {
122
+ "pre-commit": "lint-staged"
123
+ }
124
+ },
125
+ "lint-staged": {
126
+ "*.{js,css,json}": [
127
+ "prettier --write",
128
+ "git add"
129
+ ],
130
+ "*.js": [
131
+ "eslint --fix",
132
+ "git add"
133
+ ]
134
+ }
135
+ }