Skip to content

Commit

Permalink
Merge pull request #1467 from glimmerjs/export-visitorKeys
Browse files Browse the repository at this point in the history
visitorKeys is needed for prettier
  • Loading branch information
NullVoxPopuli authored Oct 27, 2023
2 parents 6b23664 + d7b4342 commit cbcc813
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 15 deletions.
2 changes: 2 additions & 0 deletions packages/@glimmer/syntax/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export type { NodeVisitor } from './lib/traversal/visitor';
export { default as Walker } from './lib/traversal/walker';
export * as ASTv1 from './lib/v1/api';
export { default as builders } from './lib/v1/public-builders';
export { default as visitorKeys } from './lib/v1/visitor-keys';
export { getVoidTags, isVoidTag } from './lib/generation/printer';
export * as ASTv2 from './lib/v2/api';
export { normalize } from './lib/v2/normalize';
export { node } from './lib/v2/objects/node';
Expand Down
35 changes: 24 additions & 11 deletions packages/@glimmer/syntax/lib/generation/printer.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
import type * as ASTv1 from '../v1/api';
import { escapeAttrValue, escapeText, sortByLoc } from './util';

export const voidMap: {
[tagName: string]: boolean;
} = Object.create(null);

let voidTagNames =
'area base br col command embed hr img input keygen link meta param source track wbr';
voidTagNames.split(' ').forEach((tagName) => {
voidMap[tagName] = true;
});
export const voidMap = new Set([
'area',
'base',
'br',
'col',
'command',
'embed',
'hr',
'img',
'input',
'keygen',
'link',
'meta',
'param',
'source',
'track',
'wbr',
]);

export function getVoidTags() {
return [...voidMap];
}

const NON_WHITESPACE = /^\S/u;

Expand Down Expand Up @@ -41,8 +54,8 @@ export interface PrinterOptions {
* Examples when false:
* - Link (component)
*/
function isVoidTag(tag: string): boolean {
return !!(voidMap[tag.toLowerCase()] && tag[0]?.toLowerCase() === tag[0]);
export function isVoidTag(tag: string): boolean {
return voidMap.has(tag.toLowerCase()) && tag[0]?.toLowerCase() === tag[0];
}

export default class Printer {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export class TokenizerEventHandlers extends HandlebarsNodeVisitors {
);
}

if (voidMap[tag.name] || tag.selfClosing) {
if (voidMap.has(tag.name) || tag.selfClosing) {
this.finishEndTag(true);
}
} else if (tag.type === 'EndTag') {
Expand Down Expand Up @@ -263,7 +263,7 @@ export class TokenizerEventHandlers extends HandlebarsNodeVisitors {
element: ASTv1.ElementNode,
selfClosing: boolean
): void {
if (voidMap[tag.name] && !selfClosing) {
if (voidMap.has(tag.name) && !selfClosing) {
// EngTag is also called by StartTag for void and self-closing tags (i.e.
// <input> or <br />, so we need to check for that here. Otherwise, we would
// throw an error for those cases.
Expand Down Expand Up @@ -299,8 +299,8 @@ export class TokenizerEventHandlers extends HandlebarsNodeVisitors {
} else {
throw generateSyntaxError(
`An unquoted attribute value must be a string or a mustache, ` +
`preceded by whitespace or a '=' character, and ` +
`followed by whitespace, a '>' character, or '/>'`,
`preceded by whitespace or a '=' character, and ` +
`followed by whitespace, a '>' character, or '/>'`,
span
);
}
Expand Down
39 changes: 39 additions & 0 deletions packages/@glimmer/syntax/test/public-api-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import * as syntax from '@glimmer/syntax';

QUnit.module('[glimmer-syntax] Public API is unchanged');

QUnit.test('exports are not accidentally removed', function(assert) {
assert.ok(syntax.print);
assert.ok(syntax.sortByLoc);
assert.ok(syntax.getTemplateLocals);
assert.ok(syntax.isKeyword);
assert.ok(syntax.KEYWORDS_TYPES);
assert.ok(syntax.src);
assert.ok(syntax.preprocess);
assert.ok(syntax.hasSpan);
assert.ok(syntax.loc);
assert.ok(syntax.maybeLoc);
assert.ok(syntax.SpanList);
assert.ok(syntax.BlockSymbolTable);
assert.ok(syntax.ProgramSymbolTable);
assert.ok(syntax.SymbolTable);
assert.ok(syntax.generateSyntaxError);
assert.ok(syntax.cannotRemoveNode);
assert.ok(syntax.cannotReplaceNode);
assert.ok(syntax.WalkerPath);
assert.ok(syntax.traverse);
assert.ok(syntax.Walker);
assert.ok(syntax.ASTv1);
assert.ok(syntax.builders);
assert.ok(syntax.visitorKeys);
assert.ok(syntax.getVoidTags);
assert.ok(syntax.isVoidTag);
assert.ok(syntax.ASTv2);
assert.ok(syntax.normalize);
assert.ok(syntax.node);
// deprecated
assert.ok(syntax.Path);
// deprecated
assert.ok(syntax.AST);

});

0 comments on commit cbcc813

Please sign in to comment.