htmljs-parser
Advanced tools
Comparing version 2.9.0 to 2.9.1
@@ -32,6 +32,8 @@ { | ||
"devDependencies": { | ||
"@babel/runtime": "^7.12.5", | ||
"chai": "^4.0.0", | ||
"colors": "^1.1.2", | ||
"jshint": "^2.8.0", | ||
"mocha": "^4.0.0" | ||
"mocha": "^4.0.0", | ||
"mocha-autotest": "^1.0.3" | ||
}, | ||
@@ -42,3 +44,3 @@ "license": "MIT", | ||
}, | ||
"version": "2.9.0" | ||
"version": "2.9.1" | ||
} |
@@ -1,14 +0,6 @@ | ||
var chai = require('chai'); | ||
chai.config.includeStack = true; | ||
require('chai').should(); | ||
var path = require('path'); | ||
var autotest = require('mocha-autotest').default; | ||
var runDirTest = require('./util/runDirTest'); | ||
describe('parser', function() { | ||
require('./util/autotest').scanDir( | ||
path.join(__dirname, 'autotest-1.x'), | ||
function (dir) { | ||
runDirTest(dir, { legacyCompatibility: true }); | ||
}); | ||
describe('parser', () => { | ||
autotest('autotest-1.x', runDirTest({ legacyCompatibility: true })); | ||
}); |
@@ -1,14 +0,6 @@ | ||
var chai = require('chai'); | ||
chai.config.includeStack = true; | ||
require('chai').should(); | ||
var path = require('path'); | ||
var autotest = require('mocha-autotest').default; | ||
var runDirTest = require('./util/runDirTest'); | ||
describe('parser', function() { | ||
require('./util/autotest').scanDir( | ||
path.join(__dirname, 'autotest'), | ||
function (dir) { | ||
runDirTest(dir, {}); | ||
}); | ||
describe('parser', () => { | ||
autotest('autotest', runDirTest({})); | ||
}); |
@@ -1,124 +0,76 @@ | ||
var path = require('path'); | ||
var fs = require('fs'); | ||
var chai = require('chai'); | ||
var TreeBuilder = require('./TreeBuilder'); | ||
var htmljs = require('../../'); | ||
var TreeBuilder = require('./TreeBuilder'); | ||
var assert = require('assert'); | ||
var updateExpectations = process.env.hasOwnProperty('UPDATE_EXPECTATIONS'); | ||
chai.config.includeStack = true; | ||
require('chai').should(); | ||
require('colors'); | ||
module.exports = function runTest(defaultParserOptions) { | ||
return function ({ test, resolve, snapshot }) { | ||
test(function() { | ||
var inputPath = resolve('input.htmljs'); | ||
var testOptionsPath = resolve('test.js'); | ||
function extend(target, source) { //A simple function to copy properties from one object to another | ||
if (!target) { //Check if a target was provided, otherwise create a new empty object to return | ||
target = {}; | ||
} | ||
var main; | ||
var inputHtmlJs; | ||
var parserOptions = defaultParserOptions; | ||
if (source) { | ||
for (var propName in source) { | ||
if (source.hasOwnProperty(propName)) { //Only look at source properties that are not inherited | ||
target[propName] = source[propName]; //Copy the property | ||
if (fs.existsSync(testOptionsPath)) { | ||
main = require(testOptionsPath); | ||
} | ||
} | ||
} | ||
return target; | ||
} | ||
if (main) { | ||
parserOptions = Object.assign({}, defaultParserOptions, main); | ||
} | ||
module.exports = function(dir, parserOptions) { | ||
var inputPath = path.join(dir, 'input.htmljs'); | ||
var testOptionsPath = path.join(dir, 'test.js'); | ||
var name = path.basename(dir); | ||
if (main && main.getSource) { | ||
inputHtmlJs = main.getSource(); | ||
} else { | ||
inputHtmlJs = fs.readFileSync(inputPath, {encoding: 'utf8'}); | ||
} | ||
var main; | ||
var inputHtmlJs; | ||
if (!main || (main.preserveLineEndings !== true)) { | ||
inputHtmlJs = inputHtmlJs.replace(/\r\n|\n/g, "\n"); | ||
} | ||
if (fs.existsSync(testOptionsPath)) { | ||
main = require(testOptionsPath); | ||
} | ||
var error; | ||
var output; | ||
if (main && main.getSource) { | ||
inputHtmlJs = main.getSource(); | ||
} else { | ||
inputHtmlJs = fs.readFileSync(inputPath, {encoding: 'utf8'}); | ||
} | ||
if (!main || (main.preserveLineEndings !== true)) { | ||
inputHtmlJs = inputHtmlJs.replace(/\r\n|\n/g, "\n"); | ||
} | ||
function parse(text, inputPath) { | ||
var treeBuilder = new TreeBuilder(text, main); | ||
var finalParserOptions = { | ||
isOpenTagOnly: function(tagName) { | ||
if (tagName === 'foo-img') { | ||
return true; | ||
try { | ||
output = parse(inputHtmlJs, inputPath, parserOptions); | ||
} catch(e) { | ||
if (main && main.checkThrownError) { | ||
return; | ||
} else { | ||
throw e; | ||
} | ||
} | ||
}; | ||
extend(finalParserOptions, parserOptions); | ||
extend(finalParserOptions, main); | ||
var parser = htmljs.createParser(treeBuilder.listeners, finalParserOptions); | ||
parser.parse(text, inputPath); | ||
return treeBuilder.toString(); | ||
if (main && main.checkThrownError) { | ||
throw new Error('Error expected!'); | ||
} else if (main && main.checkOutput) { | ||
main.checkOutput(output); | ||
} else { | ||
snapshot(output, { ext: ".html" }); | ||
} | ||
}); | ||
} | ||
}; | ||
function checkOutput(actual) { | ||
var suffix = '.html'; | ||
var actualPath = path.join(dir, 'actual' + suffix); | ||
var expectedPath = path.join(dir, 'expected' + suffix); | ||
function parse(text, inputPath, parserOptions) { | ||
var treeBuilder = new TreeBuilder(text, parserOptions); | ||
fs.writeFileSync(actualPath, suffix === '.json' ? JSON.stringify(actual, null, 4) : actual, {encoding: 'utf8'}); | ||
var expected; | ||
try { | ||
expected = fs.readFileSync(expectedPath, { encoding: 'utf8' }); | ||
} catch(e) { | ||
expected = suffix === '.json' ? '"TBD"' : 'TBD'; | ||
fs.writeFileSync(expectedPath, expected, {encoding: 'utf8'}); | ||
} | ||
if (suffix === '.json') { | ||
var expectedObject = JSON.parse(expected); | ||
assert.deepEqual(actual, expectedObject); | ||
} else { | ||
if (actual !== expected) { | ||
if (updateExpectations) { | ||
fs.writeFileSync(expectedPath, actual, { encoding: 'utf8' }); | ||
} else { | ||
assert.deepEqual(actual, expected); | ||
} | ||
var finalParserOptions = Object.assign({ | ||
isOpenTagOnly: function(tagName) { | ||
if (tagName === 'foo-img') { | ||
return true; | ||
} | ||
} | ||
} | ||
}, parserOptions); | ||
if (main && main.checkThrownError) { | ||
var error; | ||
var parser = htmljs.createParser(treeBuilder.listeners, finalParserOptions); | ||
try { | ||
parse(inputHtmlJs, inputPath); | ||
} catch(e) { | ||
error = e; | ||
} | ||
parser.parse(text, inputPath); | ||
if (!error) { | ||
throw new Error('Error expected!'); | ||
} else { | ||
} | ||
} else { | ||
var output = parse(inputHtmlJs, inputPath); | ||
if (main && main.checkOutput) { | ||
main.checkOutput(output); | ||
} else { | ||
checkOutput(output); | ||
} | ||
} | ||
}; | ||
return treeBuilder.toString(); | ||
} |
@@ -16,3 +16,3 @@ 'use strict'; | ||
i = 1; | ||
result = attributeAssignmentToString(attr, includeLiteralValues); | ||
result = " DEFAULT" + attributeAssignmentToString(attr, includeLiteralValues); | ||
} | ||
@@ -144,18 +144,20 @@ | ||
var str = '<' + tagName; | ||
var str = '<'; | ||
if (tagNameExpression) { | ||
str += '[' + tagNameExpression + ']'; | ||
str += '(' + tagNameExpression + ')'; | ||
} else { | ||
str += tagName; | ||
} | ||
if (variable) { | ||
str += '/(' + variable.value + ')'; | ||
str += ' VAR=(' + variable.value + ')'; | ||
} | ||
if (argument) { | ||
str += '(' + argument.value + ')'; | ||
str += ' ARGS=(' + argument.value + ')'; | ||
} | ||
if (params) { | ||
str += '|' + params.value + '|'; | ||
str += ' PARAMS=(' + params.value + ')'; | ||
} | ||
@@ -162,0 +164,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
1000
2
256485
6
3857