hast-util-from-parse5
Advanced tools
Comparing version 3.0.0 to 4.0.0
48
index.js
'use strict' | ||
var information = require('property-information') | ||
var camelcase = require('camelcase') | ||
var html = require('property-information/html') | ||
var svg = require('property-information/svg') | ||
var find = require('property-information/find') | ||
var h = require('hastscript') | ||
@@ -35,2 +36,3 @@ var xtend = require('xtend') | ||
return transform(ast, { | ||
schema: settings.space === 'svg' ? svg : html, | ||
file: file, | ||
@@ -44,2 +46,3 @@ verbose: settings.verbose, | ||
function transform(ast, config) { | ||
var schema = config.schema | ||
var fn = own.call(map, ast.nodeName) ? map[ast.nodeName] : element | ||
@@ -50,2 +53,6 @@ var children | ||
if (fn === element && schema.space === 'html' && ast.nodeName === 'svg') { | ||
config.schema = svg | ||
} | ||
if (ast.childNodes) { | ||
@@ -58,3 +65,3 @@ children = nodes(ast.childNodes, config) | ||
if (ast.sourceCodeLocation && config.file) { | ||
pos = location(node, ast.sourceCodeLocation, config.verbose) | ||
pos = location(node, ast.sourceCodeLocation, config) | ||
@@ -67,2 +74,4 @@ if (pos) { | ||
config.schema = schema | ||
return node | ||
@@ -130,7 +139,9 @@ } | ||
function element(ast, children, config) { | ||
var name = ast.tagName | ||
var attributes = ast.attrs | ||
var length = attributes.length | ||
var props = {} | ||
var values = ast.attrs | ||
var length = values.length | ||
var index = -1 | ||
var attr | ||
var attribute | ||
var prop | ||
var node | ||
@@ -142,9 +153,10 @@ var pos | ||
while (++index < length) { | ||
attr = values[index] | ||
props[(attr.prefix ? attr.prefix + ':' : '') + attr.name] = attr.value | ||
attribute = attributes[index] | ||
prop = (attribute.prefix ? attribute.prefix + ':' : '') + attribute.name | ||
props[prop] = attribute.value | ||
} | ||
node = h(ast.tagName, props, children) | ||
node = h(name, props, children) | ||
if (ast.nodeName === 'template' && 'content' in ast) { | ||
if (name === 'template' && 'content' in ast) { | ||
pos = ast.sourceCodeLocation | ||
@@ -165,9 +177,11 @@ start = pos && pos.startTag && position(pos.startTag).end | ||
/* Create clean positional information. */ | ||
function location(node, location, verbose) { | ||
function location(node, location, config) { | ||
var schema = config.schema | ||
var verbose = config.verbose | ||
var pos = position(location) | ||
var reference | ||
var values | ||
var attributes | ||
var attribute | ||
var props | ||
var prop | ||
var name | ||
@@ -188,8 +202,8 @@ if (node.type === 'element') { | ||
if (verbose) { | ||
values = location.attrs | ||
attributes = location.attrs | ||
props = {} | ||
for (prop in values) { | ||
name = (information(prop) || {}).propertyName || camelcase(prop) | ||
props[name] = position(values[prop]) | ||
for (attribute in attributes) { | ||
prop = find(schema, attribute).property | ||
props[prop] = position(attributes[attribute]) | ||
} | ||
@@ -196,0 +210,0 @@ |
{ | ||
"name": "hast-util-from-parse5", | ||
"version": "3.0.0", | ||
"version": "4.0.0", | ||
"description": "Transform Parse5’s AST to HAST", | ||
@@ -22,6 +22,5 @@ "license": "MIT", | ||
"dependencies": { | ||
"camelcase": "^5.0.0", | ||
"ccount": "^1.0.3", | ||
"hastscript": "^3.0.0", | ||
"property-information": "^3.1.0", | ||
"hastscript": "^4.0.0", | ||
"property-information": "^4.0.0", | ||
"xtend": "^4.0.1" | ||
@@ -43,4 +42,4 @@ }, | ||
"tape": "^4.0.0", | ||
"to-vfile": "^5.0.0", | ||
"unist-util-visit": "^1.1.3", | ||
"vfile": "^3.0.0", | ||
"xo": "^0.21.0" | ||
@@ -47,0 +46,0 @@ }, |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
12168
4
189
0
+ Addedhastscript@4.1.0(transitive)
+ Addedproperty-information@4.2.0(transitive)
- Removedcamelcase@^5.0.0
- Removedcamelcase@3.0.05.3.1(transitive)
- Removedhastscript@3.1.0(transitive)
- Removedproperty-information@3.2.0(transitive)
Updatedhastscript@^4.0.0
Updatedproperty-information@^4.0.0