Convert src/compiler/compile/utils/nodes_to_template_literal.ts to JavaScript

pull/8569/head
Simon Holthausen 3 years ago
parent a2e2bacb3a
commit 2c9b1ea776

@ -1,6 +1,7 @@
import { roles as roles_map, elementRoles } from 'aria-query';
import { AXObjects, AXObjectRoles, elementAXObjects } from 'axobject-query';
import { regex_whitespaces } from '../../utils/patterns.js';
const aria_roles = roles_map.keys();
const abstract_roles = new Set(aria_roles.filter((role) => roles_map.get(role).abstract));
const non_abstract_roles = aria_roles.filter((name) => !abstract_roles.has(name));
@ -33,21 +34,21 @@ const interactive_roles = new Set(
);
/**
* @param {ARIARoleDefinitionKey} role
* @param {import('aria-query').ARIARoleDefinitionKey} role
*/
export function is_non_interactive_roles(role) {
return non_interactive_roles.has(role);
}
/**
* @param {ARIARoleDefinitionKey} role
* @param {import('aria-query').ARIARoleDefinitionKey} role
*/
export function is_interactive_roles(role) {
return interactive_roles.has(role);
}
/**
* @param {ARIARoleDefinitionKey} role
* @param {import('aria-query').ARIARoleDefinitionKey} role
*/
export function is_abstract_role(role) {
return abstract_roles.has(role);
@ -55,7 +56,7 @@ export function is_abstract_role(role) {
const presentation_roles = new Set(['presentation', 'none']);
/**
* @param {ARIARoleDefinitionKey} role
* @param {import('aria-query').ARIARoleDefinitionKey} role
*/
export function is_presentation_role(role) {
return presentation_roles.has(role);
@ -63,7 +64,7 @@ export function is_presentation_role(role) {
/**
* @param {string} tag_name
* @param {Map<string, Attribute>} attribute_map
* @param {Map<string, import('../nodes/Attribute.js').default>} attribute_map
*/
export function is_hidden_from_screen_reader(tag_name, attribute_map) {
if (tag_name === 'input') {
@ -80,7 +81,7 @@ export function is_hidden_from_screen_reader(tag_name, attribute_map) {
}
/**
* @param {Map<string, Attribute>} attribute_map
* @param {Map<string, import('../nodes/Attribute.js').default>} attribute_map
*/
export function has_disabled_attribute(attribute_map) {
const disabled_attr = attribute_map.get('disabled');
@ -99,7 +100,7 @@ export function has_disabled_attribute(attribute_map) {
}
/**
* @type {ARIARoleRelationConcept[]}
* @type {import('aria-query').ARIARoleRelationConcept[]}
*/
const non_interactive_element_role_schemas = [];
elementRoles.entries().forEach(([schema, roles]) => {
@ -109,7 +110,7 @@ elementRoles.entries().forEach(([schema, roles]) => {
});
/**
* @type {ARIARoleRelationConcept[]}
* @type {import('aria-query').ARIARoleRelationConcept[]}
*/
const interactive_element_role_schemas = [];
elementRoles.entries().forEach(([schema, roles]) => {
@ -127,7 +128,7 @@ const non_interactive_ax_objects = new Set(
);
/**
* @type {ARIARoleRelationConcept[]}
* @type {import('aria-query').ARIARoleRelationConcept[]}
*/
const interactive_element_ax_object_schemas = [];
elementAXObjects.entries().forEach(([schema, ax_object]) => {
@ -137,7 +138,7 @@ elementAXObjects.entries().forEach(([schema, ax_object]) => {
});
/**
* @type {ARIARoleRelationConcept[]}
* @type {import('aria-query').ARIARoleRelationConcept[]}
*/
const non_interactive_element_ax_object_schemas = [];
elementAXObjects.entries().forEach(([schema, ax_object]) => {
@ -147,9 +148,9 @@ elementAXObjects.entries().forEach(([schema, ax_object]) => {
});
/**
* @param {ARIARoleRelationConcept} schema
* @param {import('aria-query').ARIARoleRelationConcept} schema
* @param {string} tag_name
* @param {Map<string, Attribute>} attribute_map
* @param {Map<string, import('../nodes/Attribute.js').default>} attribute_map
*/
function match_schema(schema, tag_name, attribute_map) {
if (schema.name !== tag_name) return false;
@ -163,17 +164,17 @@ function match_schema(schema, tag_name, attribute_map) {
return true;
});
}
export var ElementInteractivity;
(function (ElementInteractivity) {
ElementInteractivity['Interactive'] = 'interactive';
ElementInteractivity['NonInteractive'] = 'non-interactive';
ElementInteractivity['Static'] = 'static';
})(ElementInteractivity || (ElementInteractivity = {}));
export const ElementInteractivity = /** @type {const} */ ({
Interactive: 'interactive',
NonInteractive: 'non-interactive',
Static: 'static'
});
/**
* @param {string} tag_name
* @param {Map<string, Attribute>} attribute_map
* @returns {import("C:/repos/svelte/svelte/a11y.ts-to-jsdoc").ElementInteractivity}
* @param {Map<string, import('../nodes/Attribute.js').default>} attribute_map
* @returns {ElementInteractivity[keyof ElementInteractivity]}
*/
export function element_interactivity(tag_name, attribute_map) {
if (
@ -208,7 +209,7 @@ export function element_interactivity(tag_name, attribute_map) {
/**
* @param {string} tag_name
* @param {Map<string, Attribute>} attribute_map
* @param {Map<string, import('../nodes/Attribute.js').default>} attribute_map
* @returns {boolean}
*/
export function is_interactive_element(tag_name, attribute_map) {
@ -217,7 +218,7 @@ export function is_interactive_element(tag_name, attribute_map) {
/**
* @param {string} tag_name
* @param {Map<string, Attribute>} attribute_map
* @param {Map<string, import('../nodes/Attribute.js').default>} attribute_map
* @returns {boolean}
*/
export function is_non_interactive_element(tag_name, attribute_map) {
@ -226,7 +227,7 @@ export function is_non_interactive_element(tag_name, attribute_map) {
/**
* @param {string} tag_name
* @param {Map<string, Attribute>} attribute_map
* @param {Map<string, import('../nodes/Attribute.js').default>} attribute_map
* @returns {boolean}
*/
export function is_static_element(tag_name, attribute_map) {
@ -234,9 +235,9 @@ export function is_static_element(tag_name, attribute_map) {
}
/**
* @param {ARIARoleDefinitionKey} role
* @param {import('aria-query').ARIARoleDefinitionKey} role
* @param {string} tag_name
* @param {Map<string, Attribute>} attribute_map
* @param {Map<string, import('../nodes/Attribute.js').default>} attribute_map
*/
export function is_semantic_role_element(role, tag_name, attribute_map) {
for (const [schema, ax_object] of elementAXObjects.entries()) {

@ -2,8 +2,8 @@ import { p, x } from 'code-red';
import { string_literal } from './stringify.js';
/**
* @param {Map<string, Attribute>} values
* @param {Block} block
* @param {Map<string, import('../nodes/Attribute.js').default>} values
* @param {import('../render_dom/Block.js').default} block
*/
export default function get_slot_data(values, block = null) {
return {
@ -25,8 +25,8 @@ export default function get_slot_data(values, block = null) {
}
/**
* @param {Block} block
* @param {Attribute} attribute
* @param {import('../render_dom/Block.js').default} block
* @param {import('../nodes/Attribute.js').default} attribute
*/
function get_value(block, attribute) {
if (attribute.is_true) return x`true`;
@ -47,8 +47,8 @@ function get_value(block, attribute) {
}
/**
* @param {Block} block
* @param {Attribute} attribute
* @param {import('../render_dom/Block.js').default} block
* @param {import('../nodes/Attribute.js').default} attribute
*/
function get_spread_value(block, attribute) {
return block ? attribute.expression.manipulate(block) : attribute.expression.node;

@ -1,29 +1,35 @@
import { TemplateElement, TemplateLiteral } from 'estree';
import { MustacheTag, Text } from '../../interfaces';
/**
* Transforms a list of Text and MustacheTags into a TemplateLiteral expression.
* Start/End positions on the elements of the expression are not set.
* @param {Array<Text | MustacheTag>} value
* @returns {import("C:/repos/svelte/svelte/node_modules/.pnpm/@types+estree@1.0.0/node_modules/@types/estree/index").TemplateLiteral}
*/
export function nodes_to_template_literal(value) {
/**
* @type {TemplateLiteral}
*/
export function nodes_to_template_literal(value: Array<Text | MustacheTag>): TemplateLiteral {
const literal: TemplateLiteral = {
const literal = {
type: 'TemplateLiteral',
expressions: [],
quasis: []
};
let quasi: TemplateElement = {
/**
* @type {TemplateElement}
*/
let quasi = {
type: 'TemplateElement',
value: { raw: '', cooked: null },
tail: false
};
value.forEach((node) => {
if (node.type === 'Text') {
quasi.value.raw += node.raw;
} else if (node.type === 'MustacheTag') {
}
else if (node.type === 'MustacheTag') {
literal.quasis.push(quasi);
literal.expressions.push(node.expression as any);
literal.expressions.push(node.expression);
quasi = {
type: 'TemplateElement',
value: { raw: '', cooked: null },
@ -35,3 +41,7 @@ export function nodes_to_template_literal(value: Array<Text | MustacheTag>): Tem
literal.quasis.push(quasi);
return literal;
}

Loading…
Cancel
Save