diff --git a/packages/pug-code-gen/babel-plugin-pug-concat.js b/packages/pug-code-gen/babel-plugin-pug-concat.js deleted file mode 100644 index 83730799a..000000000 --- a/packages/pug-code-gen/babel-plugin-pug-concat.js +++ /dev/null @@ -1,93 +0,0 @@ -'use strict'; - -var t = require('babel-types'); -var stringify = require('js-stringify'); - -function isPugAssignment(path) { - if (!t.isAssignmentExpression(path)) { - return; - } - if (!t.isIdentifier(path.get('left')) || - path.get('left.name').node !== 'pug_html') { - return; - } - if (!t.isBinaryExpression(path.get('right')) || - !t.isIdentifier(path.get('right.left')) || - path.get('right.left.name').node !== 'pug_html') { - return; - } - return true; -} - -module.exports = function () { - return { - visitor: { - ExpressionStatement(path) { - // only lists of assignments need compaction - if (!path.inList) { - return; - } - let first = path.get('expression'); - - // compaction is started only upon a specific pug buffer assignment - if (!isPugAssignment(first)) { - return; - } - - // the first assignment in a list was found. - // compact siblings (max N) - let N = 100; - let fragment = [t.identifier('pug_html')]; - let litSerie = false - let litValue = ''; - let bufferNode = first.get('right.right').node; - if (t.isStringLiteral(bufferNode)) { - litSerie = true; - litValue = bufferNode.value; - } else { - fragment.push(bufferNode); - } - - let sibling = path.getSibling(path.key + 1); - let count = 0; - let expr; - while (--N>0 &&t.isExpressionStatement(sibling) && isPugAssignment(expr = sibling.get('expression'))) { - count++; - bufferNode = expr.get('right.right').node; - if (t.isStringLiteral(bufferNode)) { - litSerie = true; - litValue += bufferNode.value; - } else { - if (litSerie) { - const lit = t.stringLiteral(litValue); - lit.extra = { rawValue: litValue, raw: stringify(litValue)} - fragment.push(lit); - litSerie = false; - litValue = ''; - } - fragment.push(bufferNode) - } - sibling.remove(); - sibling = path.getSibling(path.key + 1); - } - - if (count == 0) { - return; - } - - if (litSerie) { - const lit = t.stringLiteral(litValue); - lit.extra = { rawValue: litValue, raw: stringify(litValue)} - fragment.push(lit); - } - - let op = fragment.reduce(function(acc, val) { - return t.binaryExpression('+', acc, val); - }); - - first.get('right').replaceWith(op) - - } - } - }; -} diff --git a/packages/pug-code-gen/index.js b/packages/pug-code-gen/index.js index c089f910b..cb944ca9e 100644 --- a/packages/pug-code-gen/index.js +++ b/packages/pug-code-gen/index.js @@ -16,8 +16,7 @@ var gen = require('babel-generator'); var babylon = require('babylon'); var babelTemplate = require('babel-template'); var babel = require('babel-core'); -var babelPluginTransformWith = require('babel-plugin-transform-with'); -var babelPluginPugConcat = require('./babel-plugin-pug-concat.js'); + // This is used to prevent pretty printing inside certain tags var WHITE_SPACE_SENSITIVE_TAGS = { pre: true, @@ -836,9 +835,6 @@ Compiler.prototype = { , self = this; var ast = []; - var bufferName = interpolated ? (tag.astExpr ? this.bufferAST(tag.astExpr) : this.bufferExpression(tag.expr)) : this.buffer(name); - -/* function bufferName() { if (interpolated) { if (tag.astExpr) return self.bufferAST(tag.astExpr); @@ -846,7 +842,7 @@ Compiler.prototype = { } else return self.buffer(name); } -*/ + if (WHITE_SPACE_SENSITIVE_TAGS[tag.name] === true) this.escapePrettyMode = true; if (!this.hasCompiledTag) { @@ -860,7 +856,7 @@ Compiler.prototype = { push.apply(ast, this.prettyIndent(0, true)); if (tag.selfClosing || (!this.xml && selfClosing[tag.name])) { push.apply(ast, this.buffer('<')); - push.apply(ast, bufferName); + push.apply(ast, bufferName()); push.apply(ast, this.visitAttributes(tag.attrs, this.attributeBlocks(tag.attributeBlocks))); if (this.terse && !tag.selfClosing) { push.apply(ast, this.buffer('>')); @@ -888,7 +884,7 @@ Compiler.prototype = { } else { // Optimize attributes buffering push.apply(ast, this.buffer('<')); - push.apply(ast, bufferName); + push.apply(ast, bufferName()); push.apply(ast, this.visitAttributes(tag.attrs, this.attributeBlocks(tag.attributeBlocks))); push.apply(ast, this.buffer('>')); if (tag.code) push.apply(ast, this.visitCode(tag.code)); @@ -899,7 +895,7 @@ Compiler.prototype = { push.apply(ast, this.prettyIndent(0, true)); push.apply(ast, this.buffer('')); } diff --git a/packages/pug-code-gen/package.json b/packages/pug-code-gen/package.json index 924dc9e22..e37799f12 100644 --- a/packages/pug-code-gen/package.json +++ b/packages/pug-code-gen/package.json @@ -8,7 +8,6 @@ "dependencies": { "babel-core": "^6.26.3", "babel-generator": "^6.26.1", - "babel-plugin-transform-with": "^1.0.0", "babel-template": "^6.26.0", "babel-types": "^6.26.0", "babylon": "^6.18.0",