permet l'ajout des frameworks et des routes

This commit is contained in:
22107988t
2023-09-25 09:41:55 +02:00
parent 0b9f7d4dfb
commit 361112699c
2787 changed files with 864804 additions and 0 deletions

View File

@@ -0,0 +1,65 @@
"use strict";
var _require = require('../constants/token-types'),
TOKEN_OPEN_TAG_END = _require.TOKEN_OPEN_TAG_END,
TOKEN_OPEN_TAG_END_SCRIPT = _require.TOKEN_OPEN_TAG_END_SCRIPT,
TOKEN_OPEN_TAG_END_STYLE = _require.TOKEN_OPEN_TAG_END_STYLE,
TOKEN_ATTRIBUTE_KEY = _require.TOKEN_ATTRIBUTE_KEY,
TOKEN_ATTRIBUTE_ASSIGNMENT = _require.TOKEN_ATTRIBUTE_ASSIGNMENT,
TOKEN_ATTRIBUTE_VALUE = _require.TOKEN_ATTRIBUTE_VALUE,
TOKEN_ATTRIBUTE_VALUE_WRAPPER_START = _require.TOKEN_ATTRIBUTE_VALUE_WRAPPER_START,
TOKEN_ATTRIBUTE_VALUE_WRAPPER_END = _require.TOKEN_ATTRIBUTE_VALUE_WRAPPER_END;
function getLastAttribute(state) {
var attributes = state.currentNode.content.attributes;
return attributes[attributes.length - 1];
}
function handleValueEnd(state) {
state.currentContext = state.currentContext.parentRef;
return state;
}
function handleAttributeValue(state, token) {
var attribute = getLastAttribute(state);
attribute.value = token;
state.caretPosition++;
return state;
}
function handleAttributeValueWrapperStart(state, token) {
var attribute = getLastAttribute(state);
attribute.startWrapper = token;
state.caretPosition++;
return state;
}
function handleAttributeValueWrapperEnd(state, token) {
var attribute = getLastAttribute(state);
attribute.endWrapper = token;
state.caretPosition++;
return state;
}
module.exports = function attributeValue(token, state) {
var VALUE_END_TOKENS = [TOKEN_OPEN_TAG_END, TOKEN_OPEN_TAG_END_SCRIPT, TOKEN_OPEN_TAG_END_STYLE, TOKEN_ATTRIBUTE_KEY, TOKEN_ATTRIBUTE_ASSIGNMENT];
if (VALUE_END_TOKENS.indexOf(token.type) !== -1) {
return handleValueEnd(state);
}
if (token.type === TOKEN_ATTRIBUTE_VALUE) {
return handleAttributeValue(state, token);
}
if (token.type === TOKEN_ATTRIBUTE_VALUE_WRAPPER_START) {
return handleAttributeValueWrapperStart(state, token);
}
if (token.type === TOKEN_ATTRIBUTE_VALUE_WRAPPER_END) {
return handleAttributeValueWrapperEnd(state, token);
}
state.caretPosition++;
return state;
};

View File

@@ -0,0 +1,69 @@
"use strict";
var _require = require('../constants/token-types'),
TOKEN_OPEN_TAG_END = _require.TOKEN_OPEN_TAG_END,
TOKEN_OPEN_TAG_END_SCRIPT = _require.TOKEN_OPEN_TAG_END_SCRIPT,
TOKEN_OPEN_TAG_END_STYLE = _require.TOKEN_OPEN_TAG_END_STYLE,
TOKEN_ATTRIBUTE_KEY = _require.TOKEN_ATTRIBUTE_KEY,
TOKEN_ATTRIBUTE_ASSIGNMENT = _require.TOKEN_ATTRIBUTE_ASSIGNMENT;
var _require2 = require('../constants/tree-constructor-contexts'),
ATTRIBUTE_VALUE_CONTEXT = _require2.ATTRIBUTE_VALUE_CONTEXT;
function getLastAttribute(state) {
var attributes = state.currentNode.content.attributes;
return attributes[attributes.length - 1];
}
function handleOpenTagEnd(state) {
state.currentContext = state.currentContext.parentRef;
return state;
}
function handleAttributeKey(state, token) {
var attribute = getLastAttribute(state);
if (attribute.key !== undefined || attribute.value !== undefined) {
state.currentContext = state.currentContext.parentRef;
return state;
}
attribute.key = token;
state.caretPosition++;
return state;
}
function handleAttributeAssignment(state) {
var attribute = getLastAttribute(state);
if (attribute.value !== undefined) {
state.currentContext = state.currentContext.parentRef;
return state;
}
state.currentContext = {
parentRef: state.currentContext,
type: ATTRIBUTE_VALUE_CONTEXT
};
state.caretPosition++;
return state;
}
module.exports = function attribute(token, state) {
var OPEN_TAG_END_TOKENS = [TOKEN_OPEN_TAG_END, TOKEN_OPEN_TAG_END_SCRIPT, TOKEN_OPEN_TAG_END_STYLE];
if (OPEN_TAG_END_TOKENS.indexOf(token.type) !== -1) {
return handleOpenTagEnd(state);
}
if (token.type === TOKEN_ATTRIBUTE_KEY) {
return handleAttributeKey(state, token);
}
if (token.type === TOKEN_ATTRIBUTE_ASSIGNMENT) {
return handleAttributeAssignment(state);
}
state.caretPosition++;
return state;
};

View File

@@ -0,0 +1,47 @@
"use strict";
var _require = require('../constants/token-types'),
TOKEN_ATTRIBUTE_KEY = _require.TOKEN_ATTRIBUTE_KEY,
TOKEN_ATTRIBUTE_ASSIGNMENT = _require.TOKEN_ATTRIBUTE_ASSIGNMENT,
TOKEN_OPEN_TAG_END = _require.TOKEN_OPEN_TAG_END,
TOKEN_OPEN_TAG_END_SCRIPT = _require.TOKEN_OPEN_TAG_END_SCRIPT,
TOKEN_OPEN_TAG_END_STYLE = _require.TOKEN_OPEN_TAG_END_STYLE;
var _require2 = require('../constants/tree-constructor-contexts'),
ATTRIBUTE_CONTEXT = _require2.ATTRIBUTE_CONTEXT;
function handlerAttributeStart(state) {
if (state.currentNode.content.attributes === undefined) {
state.currentNode.content.attributes = [];
} // new empty attribute
state.currentNode.content.attributes.push({});
state.currentContext = {
parentRef: state.currentContext,
type: ATTRIBUTE_CONTEXT
};
return state;
}
function handleOpenTagEnd(state) {
state.currentContext = state.currentContext.parentRef;
return state;
}
module.exports = function attributes(token, state) {
var ATTRIBUTE_START_TOKENS = [TOKEN_ATTRIBUTE_KEY, TOKEN_ATTRIBUTE_ASSIGNMENT];
if (ATTRIBUTE_START_TOKENS.indexOf(token.type) !== -1) {
return handlerAttributeStart(state);
}
var ATTRIBUTES_END_TOKENS = [TOKEN_OPEN_TAG_END, TOKEN_OPEN_TAG_END_SCRIPT, TOKEN_OPEN_TAG_END_STYLE];
if (ATTRIBUTES_END_TOKENS.indexOf(token.type) !== -1) {
return handleOpenTagEnd(state);
}
state.caretPosition++;
return state;
};

View File

@@ -0,0 +1,43 @@
"use strict";
var _require = require('../constants/token-types'),
TOKEN_COMMENT_START = _require.TOKEN_COMMENT_START,
TOKEN_COMMENT_END = _require.TOKEN_COMMENT_END,
TOKEN_COMMENT_CONTENT = _require.TOKEN_COMMENT_CONTENT;
function handleCommentStart(state, token) {
state.currentNode.content.start = token;
state.caretPosition++;
return state;
}
function handleCommentContent(state, token) {
state.currentNode.content.value = token;
state.caretPosition++;
return state;
}
function handleCommentEnd(state, token) {
state.currentNode.content.end = token;
state.currentNode = state.currentNode.parentRef;
state.currentContext = state.currentContext.parentRef;
state.caretPosition++;
return state;
}
module.exports = function comment(token, state) {
if (token.type === TOKEN_COMMENT_START) {
return handleCommentStart(state, token);
}
if (token.type === TOKEN_COMMENT_CONTENT) {
return handleCommentContent(state, token);
}
if (token.type === TOKEN_COMMENT_END) {
return handleCommentEnd(state, token);
}
state.caretPosition++;
return state;
};

View File

@@ -0,0 +1,72 @@
"use strict";
var _require = require('../constants/token-types'),
TOKEN_DOCTYPE_END = _require.TOKEN_DOCTYPE_END,
TOKEN_DOCTYPE_ATTRIBUTE = _require.TOKEN_DOCTYPE_ATTRIBUTE,
TOKEN_DOCTYPE_ATTRIBUTE_WRAPPER_START = _require.TOKEN_DOCTYPE_ATTRIBUTE_WRAPPER_START,
TOKEN_DOCTYPE_ATTRIBUTE_WRAPPER_END = _require.TOKEN_DOCTYPE_ATTRIBUTE_WRAPPER_END;
function getLastAttribute(state) {
var attributes = state.currentNode.content.attributes;
return attributes[attributes.length - 1];
}
function handleDoctypeEnd(state) {
state.currentContext = state.currentContext.parentRef;
return state;
}
function handleAttributeValue(state, token) {
var attribute = getLastAttribute(state);
if (attribute.value !== undefined) {
state.currentContext = state.currentContext.parentRef;
return state;
}
attribute.value = token;
state.caretPosition++;
return state;
}
function handleAttributeWrapperStart(state, token) {
var attribute = getLastAttribute(state);
if (attribute.start !== undefined || attribute.value !== undefined) {
state.currentContext = state.currentContext.parentRef;
return state;
}
attribute.startWrapper = token;
state.caretPosition++;
return state;
}
function handleAttributeWrapperEnd(state, token) {
var attribute = getLastAttribute(state);
attribute.endWrapper = token;
state.currentContext = state.currentContext.parentRef;
state.caretPosition++;
return state;
}
module.exports = function doctypeAttribute(token, state) {
if (token.type === TOKEN_DOCTYPE_END) {
return handleDoctypeEnd(state, token);
}
if (token.type === TOKEN_DOCTYPE_ATTRIBUTE_WRAPPER_START) {
return handleAttributeWrapperStart(state, token);
}
if (token.type === TOKEN_DOCTYPE_ATTRIBUTE_WRAPPER_END) {
return handleAttributeWrapperEnd(state, token);
}
if (token.type === TOKEN_DOCTYPE_ATTRIBUTE) {
return handleAttributeValue(state, token);
}
state.caretPosition++;
return state;
};

View File

@@ -0,0 +1,43 @@
"use strict";
var _require = require('../constants/tree-constructor-contexts'),
DOCTYPE_ATTRIBUTE_CONTEXT = _require.DOCTYPE_ATTRIBUTE_CONTEXT;
var _require2 = require('../constants/token-types'),
TOKEN_DOCTYPE_END = _require2.TOKEN_DOCTYPE_END,
TOKEN_DOCTYPE_ATTRIBUTE = _require2.TOKEN_DOCTYPE_ATTRIBUTE,
TOKEN_DOCTYPE_ATTRIBUTE_WRAPPER_START = _require2.TOKEN_DOCTYPE_ATTRIBUTE_WRAPPER_START;
function handleDoctypeEnd(state) {
state.currentContext = state.currentContext.parentRef;
return state;
}
function handleAttribute(state) {
if (state.currentNode.content.attributes === undefined) {
state.currentNode.content.attributes = [];
} // new empty attribute
state.currentNode.content.attributes.push({});
state.currentContext = {
type: DOCTYPE_ATTRIBUTE_CONTEXT,
parentRef: state.currentContext
};
return state;
}
module.exports = function doctypeAttributes(token, state) {
if (token.type === TOKEN_DOCTYPE_END) {
return handleDoctypeEnd(state, token);
}
var ATTRIBUTE_START_TOKENS = [TOKEN_DOCTYPE_ATTRIBUTE_WRAPPER_START, TOKEN_DOCTYPE_ATTRIBUTE];
if (ATTRIBUTE_START_TOKENS.indexOf(token.type) !== -1) {
return handleAttribute(state, token);
}
state.caretPosition++;
return state;
};

View File

@@ -0,0 +1,51 @@
"use strict";
var _require = require('../constants/token-types'),
TOKEN_DOCTYPE_END = _require.TOKEN_DOCTYPE_END,
TOKEN_DOCTYPE_ATTRIBUTE = _require.TOKEN_DOCTYPE_ATTRIBUTE,
TOKEN_DOCTYPE_START = _require.TOKEN_DOCTYPE_START,
TOKEN_DOCTYPE_ATTRIBUTE_WRAPPER_START = _require.TOKEN_DOCTYPE_ATTRIBUTE_WRAPPER_START;
var _require2 = require('../constants/tree-constructor-contexts'),
DOCTYPE_ATTRIBUTES_CONTEXT = _require2.DOCTYPE_ATTRIBUTES_CONTEXT;
function handleDoctypeStart(state, token) {
state.currentNode.content.start = token;
state.caretPosition++;
return state;
}
function handleDoctypeEnd(state, token) {
state.currentNode.content.end = token;
state.currentNode = state.currentNode.parentRef;
state.currentContext = state.currentContext.parentRef;
state.caretPosition++;
return state;
}
function handleDoctypeAttributes(state) {
state.currentContext = {
parentRef: state.currentContext,
type: DOCTYPE_ATTRIBUTES_CONTEXT
};
return state;
}
module.exports = function doctype(token, state) {
if (token.type === TOKEN_DOCTYPE_START) {
return handleDoctypeStart(state, token);
}
if (token.type === TOKEN_DOCTYPE_END) {
return handleDoctypeEnd(state, token);
}
var ATTRIBUTES_START_TOKENS = [TOKEN_DOCTYPE_ATTRIBUTE_WRAPPER_START, TOKEN_DOCTYPE_ATTRIBUTE];
if (ATTRIBUTES_START_TOKENS.indexOf(token.type) !== -1) {
return handleDoctypeAttributes(state, token);
}
state.caretPosition++;
return state;
};

View File

@@ -0,0 +1,73 @@
"use strict";
var _require = require('../constants/token-types'),
TOKEN_OPEN_TAG_START_SCRIPT = _require.TOKEN_OPEN_TAG_START_SCRIPT,
TOKEN_OPEN_TAG_END_SCRIPT = _require.TOKEN_OPEN_TAG_END_SCRIPT,
TOKEN_CLOSE_TAG_SCRIPT = _require.TOKEN_CLOSE_TAG_SCRIPT,
TOKEN_ATTRIBUTE_KEY = _require.TOKEN_ATTRIBUTE_KEY,
TOKEN_ATTRIBUTE_ASSIGNMENT = _require.TOKEN_ATTRIBUTE_ASSIGNMENT,
TOKEN_SCRIPT_TAG_CONTENT = _require.TOKEN_SCRIPT_TAG_CONTENT;
var _require2 = require('../constants/tree-constructor-contexts'),
ATTRIBUTES_CONTEXT = _require2.ATTRIBUTES_CONTEXT;
function handleOpenTagStartScript(state, token) {
state.currentNode.content.openStart = token;
state.caretPosition++;
return state;
}
function handleAttributeStartScript(state) {
state.currentContext = {
parentRef: state.currentContext,
type: ATTRIBUTES_CONTEXT
};
return state;
}
function handleOpenTagEndScript(state, token) {
state.currentNode.content.openEnd = token;
state.caretPosition++;
return state;
}
function handleScriptContent(state, token) {
state.currentNode.content.value = token;
state.caretPosition++;
return state;
}
function handleCloseTagScript(state, token) {
state.currentNode.content.close = token;
state.currentNode = state.currentNode.parentRef;
state.currentContext = state.currentContext.parentRef;
state.caretPosition++;
return state;
}
module.exports = function scriptTag(token, state) {
if (token.type === TOKEN_OPEN_TAG_START_SCRIPT) {
return handleOpenTagStartScript(state, token);
}
var ATTRIBUTE_START_TOKENS = [TOKEN_ATTRIBUTE_KEY, TOKEN_ATTRIBUTE_ASSIGNMENT];
if (ATTRIBUTE_START_TOKENS.indexOf(token.type) !== -1) {
return handleAttributeStartScript(state);
}
if (token.type === TOKEN_OPEN_TAG_END_SCRIPT) {
return handleOpenTagEndScript(state, token);
}
if (token.type === TOKEN_SCRIPT_TAG_CONTENT) {
return handleScriptContent(state, token);
}
if (token.type === TOKEN_CLOSE_TAG_SCRIPT) {
return handleCloseTagScript(state, token);
}
state.caretPosition++;
return state;
};

View File

@@ -0,0 +1,73 @@
"use strict";
var _require = require('../constants/token-types'),
TOKEN_OPEN_TAG_START_STYLE = _require.TOKEN_OPEN_TAG_START_STYLE,
TOKEN_OPEN_TAG_END_STYLE = _require.TOKEN_OPEN_TAG_END_STYLE,
TOKEN_CLOSE_TAG_STYLE = _require.TOKEN_CLOSE_TAG_STYLE,
TOKEN_ATTRIBUTE_KEY = _require.TOKEN_ATTRIBUTE_KEY,
TOKEN_ATTRIBUTE_ASSIGNMENT = _require.TOKEN_ATTRIBUTE_ASSIGNMENT,
TOKEN_STYLE_TAG_CONTENT = _require.TOKEN_STYLE_TAG_CONTENT;
var _require2 = require('../constants/tree-constructor-contexts'),
ATTRIBUTES_CONTEXT = _require2.ATTRIBUTES_CONTEXT;
function handleOpenTagStartStyle(state, token) {
state.currentNode.content.openStart = token;
state.caretPosition++;
return state;
}
function handleAttributeStartStyle(state) {
state.currentContext = {
parentRef: state.currentContext,
type: ATTRIBUTES_CONTEXT
};
return state;
}
function handleOpenTagEndStyle(state, token) {
state.currentNode.content.openEnd = token;
state.caretPosition++;
return state;
}
function handleStyleContent(state, token) {
state.currentNode.content.value = token;
state.caretPosition++;
return state;
}
function handleCloseTagStyle(state, token) {
state.currentNode.content.close = token;
state.currentNode = state.currentNode.parentRef;
state.currentContext = state.currentContext.parentRef;
state.caretPosition++;
return state;
}
module.exports = function styleTag(token, state) {
if (token.type === TOKEN_OPEN_TAG_START_STYLE) {
return handleOpenTagStartStyle(state, token);
}
var ATTRIBUTE_START_TOKENS = [TOKEN_ATTRIBUTE_KEY, TOKEN_ATTRIBUTE_ASSIGNMENT];
if (ATTRIBUTE_START_TOKENS.indexOf(token.type) !== -1) {
return handleAttributeStartStyle(state);
}
if (token.type === TOKEN_OPEN_TAG_END_STYLE) {
return handleOpenTagEndStyle(state, token);
}
if (token.type === TOKEN_STYLE_TAG_CONTENT) {
return handleStyleContent(state, token);
}
if (token.type === TOKEN_CLOSE_TAG_STYLE) {
return handleCloseTagStyle(state, token);
}
state.caretPosition++;
return state;
};

View File

@@ -0,0 +1,184 @@
"use strict";
var parseCloseTagName = require('../helpers').parseCloseTagName;
var _require = require('../constants/token-types'),
TOKEN_OPEN_TAG_START = _require.TOKEN_OPEN_TAG_START,
TOKEN_CLOSE_TAG = _require.TOKEN_CLOSE_TAG,
TOKEN_COMMENT_START = _require.TOKEN_COMMENT_START,
TOKEN_DOCTYPE_START = _require.TOKEN_DOCTYPE_START,
TOKEN_TEXT = _require.TOKEN_TEXT,
TOKEN_OPEN_TAG_START_SCRIPT = _require.TOKEN_OPEN_TAG_START_SCRIPT,
TOKEN_OPEN_TAG_START_STYLE = _require.TOKEN_OPEN_TAG_START_STYLE;
var _require2 = require('../constants/tree-constructor-contexts'),
TAG_CONTEXT = _require2.TAG_CONTEXT,
COMMENT_CONTEXT = _require2.COMMENT_CONTEXT,
DOCTYPE_CONTEXT = _require2.DOCTYPE_CONTEXT,
SCRIPT_TAG_CONTEXT = _require2.SCRIPT_TAG_CONTEXT,
STYLE_TAG_CONTEXT = _require2.STYLE_TAG_CONTEXT;
var _require3 = require('../constants/ast-nodes'),
NODE_TAG = _require3.NODE_TAG,
NODE_TEXT = _require3.NODE_TEXT,
NODE_DOCTYPE = _require3.NODE_DOCTYPE,
NODE_COMMENT = _require3.NODE_COMMENT,
NODE_SCRIPT = _require3.NODE_SCRIPT,
NODE_STYLE = _require3.NODE_STYLE;
function handleOpenTagStart(state) {
if (state.currentNode.content.children === undefined) {
state.currentNode.content.children = [];
}
var tagNode = {
nodeType: NODE_TAG,
parentRef: state.currentNode,
content: {}
};
state.currentNode.content.children.push(tagNode);
state.currentNode = tagNode;
state.currentContext = {
parentRef: state.currentContext,
type: TAG_CONTEXT
};
return state;
}
function handleCloseTag(state, token) {
var closeTagName = parseCloseTagName(token.content);
if (closeTagName !== state.currentNode.content.name) {
state.caretPosition++;
return state;
}
state.currentContext = state.currentContext.parentRef;
return state;
}
function handleCommentStart(state) {
if (state.currentNode.content.children === undefined) {
state.currentNode.content.children = [];
}
var commentNode = {
nodeType: NODE_COMMENT,
parentRef: state.currentNode,
content: {}
};
state.currentNode.content.children.push(commentNode);
state.currentNode = commentNode;
state.currentContext = {
parentRef: state.currentContext,
type: COMMENT_CONTEXT
};
return state;
}
function handleDoctypeStart(state) {
if (state.currentNode.content.children === undefined) {
state.currentNode.content.children = [];
}
var doctypeNode = {
nodeType: NODE_DOCTYPE,
parentRef: state.currentNode,
content: {}
};
state.currentNode.content.children.push(doctypeNode);
state.currentNode = doctypeNode;
state.currentContext = {
parentRef: state.currentContext,
type: DOCTYPE_CONTEXT
};
return state;
}
function handleText(state, token) {
if (state.currentNode.content.children === undefined) {
state.currentNode.content.children = [];
}
var textNode = {
nodeType: NODE_TEXT,
parentRef: state.currentNode,
content: {
value: token
}
};
state.currentNode.content.children.push(textNode);
state.caretPosition++;
return state;
}
function handleOpenTagStartScript(state) {
if (state.currentNode.content.children === undefined) {
state.currentNode.content.children = [];
}
var scriptNode = {
nodeType: NODE_SCRIPT,
parentRef: state.currentNode,
content: {}
};
state.currentNode.content.children.push(scriptNode);
state.currentNode = scriptNode;
state.currentContext = {
type: SCRIPT_TAG_CONTEXT,
parentRef: state.currentContext
};
return state;
}
function handleOpenTagStartStyle(state) {
if (state.currentNode.content.children === undefined) {
state.currentNode.content.children = [];
}
var styleNode = {
nodeType: NODE_STYLE,
parentRef: state.currentNode,
content: {}
};
state.currentNode.content.children.push(styleNode);
state.currentNode = styleNode;
state.currentContext = {
type: STYLE_TAG_CONTEXT,
parentRef: state.currentContext
};
return state;
}
module.exports = function tagContent(token, state) {
if (token.type === TOKEN_OPEN_TAG_START) {
return handleOpenTagStart(state, token);
}
if (token.type === TOKEN_TEXT) {
return handleText(state, token);
}
if (token.type === TOKEN_CLOSE_TAG) {
return handleCloseTag(state, token);
}
if (token.type === TOKEN_COMMENT_START) {
return handleCommentStart(state, token);
}
if (token.type === TOKEN_DOCTYPE_START) {
return handleDoctypeStart(state, token);
}
if (token.type === TOKEN_OPEN_TAG_START_SCRIPT) {
return handleOpenTagStartScript(state, token);
}
if (token.type === TOKEN_OPEN_TAG_START_STYLE) {
return handleOpenTagStartStyle(state, token);
}
state.caretPosition++;
return state;
};

View File

@@ -0,0 +1,27 @@
"use strict";
/**
* Parser for 'tag-name' context.
* Parses tag name from 'open-tag-start' (<div)
* token and save the tag name as self content.
* Ignores tokens others than 'open-tag-start'.
*/
var parseOpenTagName = require('../helpers').parseOpenTagName;
var _require = require('../constants/token-types'),
TOKEN_OPEN_TAG_START = _require.TOKEN_OPEN_TAG_START;
function handleTagOpenStart(state, token) {
state.currentNode.content.name = parseOpenTagName(token.content);
state.currentContext = state.currentContext.parentRef;
return state;
}
module.exports = function tagName(token, state) {
if (token.type === TOKEN_OPEN_TAG_START) {
handleTagOpenStart(state, token);
}
state.caretPosition++;
return state;
};

View File

@@ -0,0 +1,83 @@
"use strict";
var _require = require('../constants/token-types'),
TOKEN_OPEN_TAG_START = _require.TOKEN_OPEN_TAG_START,
TOKEN_OPEN_TAG_END = _require.TOKEN_OPEN_TAG_END,
TOKEN_CLOSE_TAG = _require.TOKEN_CLOSE_TAG,
TOKEN_ATTRIBUTE_KEY = _require.TOKEN_ATTRIBUTE_KEY,
TOKEN_ATTRIBUTE_ASSIGNMENT = _require.TOKEN_ATTRIBUTE_ASSIGNMENT;
var _require2 = require('../constants/tree-constructor-contexts'),
TAG_NAME_CONTEXT = _require2.TAG_NAME_CONTEXT,
ATTRIBUTES_CONTEXT = _require2.ATTRIBUTES_CONTEXT,
TAG_CONTENT_CONTEXT = _require2.TAG_CONTENT_CONTEXT;
function handleOpenTagStart(state, token) {
state.currentNode.content.openStart = token;
state.currentContext = {
parentRef: state.currentContext,
type: TAG_NAME_CONTEXT
};
return state;
}
function handleAttributeStart(state) {
state.currentContext = {
parentRef: state.currentContext,
type: ATTRIBUTES_CONTEXT
};
return state;
}
function handleOpenTagEnd(state, token) {
var SELF_CLOSING_TAGS = ['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr'];
var tagName = state.currentNode.content.name;
state.currentNode.content.openEnd = token;
if (SELF_CLOSING_TAGS.indexOf(tagName) !== -1) {
state.currentNode.content.selfClosing = true;
state.currentNode = state.currentNode.parentRef;
state.currentContext = state.currentContext.parentRef;
state.caretPosition++;
return state;
}
state.currentNode.content.selfClosing = false;
state.currentContext = {
parentRef: state.currentContext,
type: TAG_CONTENT_CONTEXT
};
state.caretPosition++;
return state;
}
function handleCloseTag(state, token) {
state.currentNode.content.close = token;
state.currentNode = state.currentNode.parentRef;
state.currentContext = state.currentContext.parentRef;
state.caretPosition++;
return state;
}
module.exports = function tag(token, state) {
if (token.type === TOKEN_OPEN_TAG_START) {
return handleOpenTagStart(state, token);
}
var ATTRIBUTE_START_TOKENS = [TOKEN_ATTRIBUTE_KEY, TOKEN_ATTRIBUTE_ASSIGNMENT];
if (ATTRIBUTE_START_TOKENS.indexOf(token.type) !== -1) {
return handleAttributeStart(state);
}
if (token.type === TOKEN_OPEN_TAG_END) {
return handleOpenTagEnd(state, token);
}
if (token.type === TOKEN_CLOSE_TAG) {
return handleCloseTag(state, token);
}
state.caretPosition++;
return state;
};