From db87d95e38c6f16fcb2edac0016a6e22328ac267 Mon Sep 17 00:00:00 2001 From: droooney Date: Wed, 20 Dec 2017 21:18:25 +0500 Subject: [PATCH] fixes #2929, update test cases --- packages/pug-filters/lib/handle-filters.js | 4 ++-- .../test/__snapshots__/index.test.js.snap | 2 +- .../test/cases/filters.include.input.json | 9 ++++++++- packages/pug-filters/test/index.test.js | 2 +- packages/pug-filters/test/update-test-cases.js | 2 +- .../test/__snapshots__/index.test.js.snap | 14 ++++++++++---- packages/pug-lexer/test/cases/filters.include.pug | 2 +- packages/pug-lexer/test/index.test.js | 2 +- .../test/__snapshots__/index.test.js.snap | 14 +++++++++++--- .../test/cases/filters.include.tokens.json | 13 +++++++------ packages/pug-strip-comments/test/index.test.js | 2 +- packages/pug/test/__snapshots__/pug.test.js.snap | 8 +++----- 12 files changed, 47 insertions(+), 27 deletions(-) diff --git a/packages/pug-filters/lib/handle-filters.js b/packages/pug-filters/lib/handle-filters.js index ce763f146..fc00fb0b4 100644 --- a/packages/pug-filters/lib/handle-filters.js +++ b/packages/pug-filters/lib/handle-filters.js @@ -19,13 +19,13 @@ function handleFilters(ast, filters, options, filterAliases) { node.type = 'Text'; node.val = filterWithFallback(node, text, attrs); } else if (node.type === 'RawInclude' && node.filters.length) { - var firstFilter = node.filters.shift(); + var firstFilter = node.filters.pop(); var attrs = getAttributes(firstFilter, options); var filename = attrs.filename = node.file.fullPath; var str = node.file.str; node.type = 'Text'; node.val = filterFileWithFallback(firstFilter, filename, str, attrs); - node.filters.forEach(function (filter) { + node.filters.slice().reverse().forEach(function (filter) { var attrs = getAttributes(filter, options); attrs.filename = filename; node.val = filterWithFallback(filter, node.val, attrs); diff --git a/packages/pug-filters/test/__snapshots__/index.test.js.snap b/packages/pug-filters/test/__snapshots__/index.test.js.snap index b304bd56b..720fd8014 100644 --- a/packages/pug-filters/test/__snapshots__/index.test.js.snap +++ b/packages/pug-filters/test/__snapshots__/index.test.js.snap @@ -404,7 +404,7 @@ exports[`test cases/filters.include.input.json 1`] = ` \"type\": \"Text\", \"line\": 7, \"filename\": \"filters.include.tokens.json\", - \"val\": \"(function() {\\n var math;\\n\\n math = {\\n square: function(value) {\\n return value * value;\\n }\\n };\\n\\n}).call(this);\\n\" + \"val\": \"\" } ], \"line\": 6, diff --git a/packages/pug-filters/test/cases/filters.include.input.json b/packages/pug-filters/test/cases/filters.include.input.json index 423856166..c6f57b176 100644 --- a/packages/pug-filters/test/cases/filters.include.input.json +++ b/packages/pug-filters/test/cases/filters.include.input.json @@ -102,6 +102,13 @@ "line": 7, "filename": "filters.include.tokens.json", "filters": [ + { + "type": "IncludeFilter", + "name": "cdata", + "attrs": [], + "line": 7, + "filename": "filters.include.tokens.json" + }, { "type": "IncludeFilter", "name": "coffee-script", @@ -150,4 +157,4 @@ ], "line": 0, "filename": "filters.include.tokens.json" -} \ No newline at end of file +} diff --git a/packages/pug-filters/test/index.test.js b/packages/pug-filters/test/index.test.js index 60e4f8efa..01115ab41 100644 --- a/packages/pug-filters/test/index.test.js +++ b/packages/pug-filters/test/index.test.js @@ -39,7 +39,7 @@ testCases.forEach(function (filename) { handleFilters(JSON.parse(read(filename)), customFilters); throw new Error('Expected ' + filename + ' to throw an exception.'); } catch (ex) { - if (!ex || !ex.code || !ex.code.indexOf('PUG:') === 0) throw ex; + if (!ex || !ex.code || ex.code.indexOf('PUG:') !== 0) throw ex; actual = { msg: ex.msg, code: ex.code, diff --git a/packages/pug-filters/test/update-test-cases.js b/packages/pug-filters/test/update-test-cases.js index dfbb56b19..e97423f3e 100644 --- a/packages/pug-filters/test/update-test-cases.js +++ b/packages/pug-filters/test/update-test-cases.js @@ -18,7 +18,7 @@ function getError (input, filename) { handleFilters(input, customFilters); throw new Error('Expected ' + filename + ' to throw an exception.'); } catch (ex) { - if (!ex || !ex.code || !ex.code.indexOf('PUG:') === 0) throw ex; + if (!ex || !ex.code || ex.code.indexOf('PUG:') !== 0) throw ex; return { msg: ex.msg, code: ex.code, diff --git a/packages/pug-lexer/test/__snapshots__/index.test.js.snap b/packages/pug-lexer/test/__snapshots__/index.test.js.snap index 3c77b05e3..c739879a2 100644 --- a/packages/pug-lexer/test/__snapshots__/index.test.js.snap +++ b/packages/pug-lexer/test/__snapshots__/index.test.js.snap @@ -6939,15 +6939,21 @@ Array [ "col": 14, "line": 7, "type": "filter", + "val": "cdata", + }, + Object { + "col": 20, + "line": 7, + "type": "filter", "val": "coffee-script", }, Object { - "col": 28, + "col": 34, "line": 7, "type": "start-attributes", }, Object { - "col": 29, + "col": 35, "line": 7, "mustEscape": true, "name": "minify", @@ -6955,12 +6961,12 @@ Array [ "val": "false", }, Object { - "col": 41, + "col": 47, "line": 7, "type": "end-attributes", }, Object { - "col": 43, + "col": 49, "line": 7, "type": "path", "val": "include-filter-coffee.coffee", diff --git a/packages/pug-lexer/test/cases/filters.include.pug b/packages/pug-lexer/test/cases/filters.include.pug index e7ea3db3d..e5083ae5f 100644 --- a/packages/pug-lexer/test/cases/filters.include.pug +++ b/packages/pug-lexer/test/cases/filters.include.pug @@ -4,4 +4,4 @@ html script include:coffee-script(minify=true) include-filter-coffee.coffee script - include:coffee-script(minify=false) include-filter-coffee.coffee + include:cdata:coffee-script(minify=false) include-filter-coffee.coffee diff --git a/packages/pug-lexer/test/index.test.js b/packages/pug-lexer/test/index.test.js index 325bbd246..19412c19f 100644 --- a/packages/pug-lexer/test/index.test.js +++ b/packages/pug-lexer/test/index.test.js @@ -24,7 +24,7 @@ fs.readdirSync(edir).forEach(function (testCase) { lex(fs.readFileSync(edir + testCase, 'utf8'), {filename: edir + testCase}); throw new Error('Expected ' + testCase + ' to throw an exception.'); } catch (ex) { - if (!ex || !ex.code || !ex.code.indexOf('PUG:') === 0) throw ex; + if (!ex || !ex.code || ex.code.indexOf('PUG:') !== 0) throw ex; actual = { msg: ex.msg, code: ex.code, diff --git a/packages/pug-parser/test/__snapshots__/index.test.js.snap b/packages/pug-parser/test/__snapshots__/index.test.js.snap index 10738aba3..f5e7c5ee2 100644 --- a/packages/pug-parser/test/__snapshots__/index.test.js.snap +++ b/packages/pug-parser/test/__snapshots__/index.test.js.snap @@ -7205,7 +7205,7 @@ Object { Object { "column": 7, "file": Object { - "column": 43, + "column": 49, "filename": "filters.include.tokens.json", "line": 7, "path": "include-filter-coffee.coffee", @@ -7213,10 +7213,18 @@ Object { }, "filename": "filters.include.tokens.json", "filters": Array [ + Object { + "attrs": Array [], + "column": 14, + "filename": "filters.include.tokens.json", + "line": 7, + "name": "cdata", + "type": "IncludeFilter", + }, Object { "attrs": Array [ Object { - "column": 29, + "column": 35, "filename": "filters.include.tokens.json", "line": 7, "mustEscape": true, @@ -7224,7 +7232,7 @@ Object { "val": "false", }, ], - "column": 14, + "column": 20, "filename": "filters.include.tokens.json", "line": 7, "name": "coffee-script", diff --git a/packages/pug-parser/test/cases/filters.include.tokens.json b/packages/pug-parser/test/cases/filters.include.tokens.json index 779425bdb..a2c1ac153 100644 --- a/packages/pug-parser/test/cases/filters.include.tokens.json +++ b/packages/pug-parser/test/cases/filters.include.tokens.json @@ -18,12 +18,13 @@ {"type":"tag","line":6,"col":5,"val":"script"} {"type":"indent","line":7,"col":1,"val":6} {"type":"include","line":7,"col":7} -{"type":"filter","line":7,"col":14,"val":"coffee-script"} -{"type":"start-attributes","line":7,"col":28} -{"type":"attribute","line":7,"col":29,"name":"minify","val":"false","mustEscape":true} -{"type":"end-attributes","line":7,"col":41} -{"type":"path","line":7,"col":43,"val":"include-filter-coffee.coffee"} +{"type":"filter","line":7,"col":14,"val":"cdata"} +{"type":"filter","line":7,"col":20,"val":"coffee-script"} +{"type":"start-attributes","line":7,"col":34} +{"type":"attribute","line":7,"col":35,"name":"minify","val":"false","mustEscape":true} +{"type":"end-attributes","line":7,"col":47} +{"type":"path","line":7,"col":49,"val":"include-filter-coffee.coffee"} {"type":"outdent","line":8,"col":5} {"type":"outdent","line":8,"col":3} {"type":"outdent","line":8,"col":1} -{"type":"eos","line":8,"col":1} \ No newline at end of file +{"type":"eos","line":8,"col":1} diff --git a/packages/pug-strip-comments/test/index.test.js b/packages/pug-strip-comments/test/index.test.js index fb0dfdea7..7f3b51c18 100644 --- a/packages/pug-strip-comments/test/index.test.js +++ b/packages/pug-strip-comments/test/index.test.js @@ -39,7 +39,7 @@ fs.readdirSync(edir).forEach(function (testCase) { strip(input); throw new Error('Expected ' + testCase + ' to throw an exception.'); } catch (ex) { - if (!ex || !ex.code || !ex.code.indexOf('PUG:') === 0) throw ex; + if (!ex || !ex.code || ex.code.indexOf('PUG:') !== 0) throw ex; expect({ msg: ex.msg, code: ex.code, diff --git a/packages/pug/test/__snapshots__/pug.test.js.snap b/packages/pug/test/__snapshots__/pug.test.js.snap index 1d90c354a..01f24328f 100644 --- a/packages/pug/test/__snapshots__/pug.test.js.snap +++ b/packages/pug/test/__snapshots__/pug.test.js.snap @@ -74,11 +74,9 @@ function pug_rethrow(n, e, r, t) { return (t == r ? \" > \" : \" \") + t + \"| \" + n; }) .join(\"\\n\"); - throw ( - (n.path = e), - (n.message = (e || \"Pug\") + \":\" + r + \"\\n\" + i + \"\\n\\n\" + n.message), - n - ); + throw ((n.path = e), + (n.message = (e || \"Pug\") + \":\" + r + \"\\n\" + i + \"\\n\\n\" + n.message), + n); } function template(locals) { var pug_html = \"\",