diff options
author | kpdecker <kpdecker@gmail.com> | 2015-04-20 02:25:53 -0500 |
---|---|---|
committer | kpdecker <kpdecker@gmail.com> | 2015-04-20 02:25:53 -0500 |
commit | 0263aa48bc8c8cdcd332edd01a644a9a0fd1cc81 (patch) | |
tree | d95e54c7af562eb22346b32f5c8b6388555e7397 /lib/precompiler.js | |
parent | ecf60ab1bfc2afb4202ec7a16f1754684825da39 (diff) | |
download | handlebars.js-0263aa48bc8c8cdcd332edd01a644a9a0fd1cc81.zip handlebars.js-0263aa48bc8c8cdcd332edd01a644a9a0fd1cc81.tar.gz handlebars.js-0263aa48bc8c8cdcd332edd01a644a9a0fd1cc81.tar.bz2 |
Run the precompiler module through es6 toolchain
Diffstat (limited to 'lib/precompiler.js')
-rw-r--r-- | lib/precompiler.js | 34 |
1 files changed, 16 insertions, 18 deletions
diff --git a/lib/precompiler.js b/lib/precompiler.js index f0955e7..48cfebd 100644 --- a/lib/precompiler.js +++ b/lib/precompiler.js @@ -1,11 +1,9 @@ /*eslint-disable no-console */ -var fs = require('fs'), - Handlebars = require('./index'), - basename = require('path').basename, - SourceMap = require('source-map'), - SourceMapConsumer = SourceMap.SourceMapConsumer, - SourceNode = SourceMap.SourceNode, - uglify = require('uglify-js'); +import fs from 'fs'; +import * as Handlebars from './handlebars'; +import {basename} from 'path'; +import {SourceMapConsumer, SourceNode} from 'source-map'; +import uglify from 'uglify-js'; module.exports.cli = function(opts) { if (opts.version) { @@ -21,7 +19,7 @@ module.exports.cli = function(opts) { try { fs.statSync(template); } catch (err) { - throw new Handlebars.Exception('Unable to open template file "' + template + '"'); + throw new Handlebars.Exception(`Unable to open template file "${template}"`); } }); @@ -33,21 +31,21 @@ module.exports.cli = function(opts) { } // Convert the known list into a hash - var known = {}; + let known = {}; if (opts.known && !Array.isArray(opts.known)) { opts.known = [opts.known]; } if (opts.known) { - for (var i = 0, len = opts.known.length; i < len; i++) { + for (let i = 0, len = opts.known.length; i < len; i++) { known[opts.known[i]] = true; } } // Build file extension pattern - var extension = opts.extension.replace(/[\\^$*+?.():=!|{}\-\[\]]/g, function(arg) { return '\\' + arg; }); + let extension = opts.extension.replace(/[\\^$*+?.():=!|{}\-\[\]]/g, function(arg) { return '\\' + arg; }); extension = new RegExp('\\.' + extension + '$'); - var output = new SourceNode(); + let output = new SourceNode(); if (!opts.simple) { if (opts.amd) { output.add('define([\'' + opts.handlebarPath + 'handlebars.runtime\'], function(Handlebars) {\n Handlebars = Handlebars["default"];'); @@ -66,24 +64,24 @@ module.exports.cli = function(opts) { output.add('{};\n'); } function processTemplate(template, root) { - var path = template, + let path = template, stat = fs.statSync(path); if (stat.isDirectory()) { fs.readdirSync(template).map(function(file) { - var childPath = template + '/' + file; + let childPath = template + '/' + file; if (extension.test(childPath) || fs.statSync(childPath).isDirectory()) { processTemplate(childPath, root || template); } }); } else { - var data = fs.readFileSync(path, 'utf8'); + let data = fs.readFileSync(path, 'utf8'); if (opts.bom && data.indexOf('\uFEFF') === 0) { data = data.substring(1); } - var options = { + let options = { knownHelpers: known, knownHelpersOnly: opts.o }; @@ -103,11 +101,11 @@ module.exports.cli = function(opts) { } template = template.replace(extension, ''); - var precompiled = Handlebars.precompile(data, options); + let precompiled = Handlebars.precompile(data, options); // If we are generating a source map, we have to reconstruct the SourceNode object if (opts.map) { - var consumer = new SourceMapConsumer(precompiled.map); + let consumer = new SourceMapConsumer(precompiled.map); precompiled = SourceNode.fromStringWithSourceMap(precompiled.code, consumer); } |