cleanup, improve comments

pull/2838/head
Bogdan Savluk 5 years ago
parent 96cf6867fd
commit fc4be88646

@ -250,7 +250,7 @@ export default class Element extends Node {
if (this.name === 'figure') {
const children = this.children.filter(node => {
if (node.type === 'Comment') return false;
if (node.type === 'Text') return /\S/.test((node as Text).data );
if (node.type === 'Text') return /\S/.test(node.data);
return true;
});
@ -391,7 +391,7 @@ export default class Element extends Node {
let ancestor = this.parent;
do {
if (ancestor.type === 'InlineComponent') break;
if (ancestor.type === 'Element' && /-/.test((ancestor as Element).name)) break;
if (ancestor.type === 'Element' && /-/.test(ancestor.name)) break;
if (ancestor.type === 'IfBlock' || ancestor.type === 'EachBlock') {
const type = ancestor.type === 'IfBlock' ? 'if' : 'each';

@ -2,7 +2,6 @@ import Node from './shared/Node';
import Component from '../Component';
import TemplateScope from './shared/TemplateScope';
import { INode } from './interfaces';
import Element from './Element';
export default class Text extends Node {
type: 'Text';
@ -16,7 +15,7 @@ export default class Text extends Node {
if (!component.component_options.preserveWhitespace && !/\S/.test(info.data)) {
let node = parent;
while (node) {
if (node.type === 'Element' && (node as Element).name === 'pre') {
if (node.type === 'Element' && node.name === 'pre') {
return;
}
node = node.parent;

@ -4,9 +4,8 @@ import Component from '../Component';
export default class Title extends Node {
type: 'Title';
should_cache: boolean;
children: Children;
should_cache: boolean;
constructor(component: Component, parent, scope, info) {
super(component, parent, scope, info);

@ -30,6 +30,8 @@ import Title from './Title';
import Transition from './Transition';
import Window from './Window';
// note: to write less types each of types in union below should have type defined as literal
// https://www.typescriptlang.org/docs/handbook/advanced-types.html#discriminated-unions
export type INode = Action
| Animation
| Attribute

@ -17,7 +17,7 @@ export default class Node {
var: string;
attributes: Attribute[];
constructor(component: Component, parent: any, scope: any, info: { start: number; end: number; type: string; }) {
constructor(component: Component, parent, scope, info: any) {
this.start = info.start;
this.end = info.end;
this.type = info.type;

@ -85,7 +85,7 @@ export default class FragmentWrapper {
// *unless* there is no whitespace between this node and its next sibling
if (this.nodes.length === 0) {
const should_trim = (
// @ts-ignore todo:
// @ts-ignore todo: probably error, should it be next_sibling.node.data?
next_sibling ? (next_sibling.node.type === 'Text' && /^\s/.test(next_sibling.data)) : !child.has_ancestor('EachBlock')
);

@ -1,5 +1,4 @@
import Component from '../../../Component';
import { Node } from '../../../../interfaces';
import { INode } from '../../../nodes/interfaces';
export default function create_debugging_comment(

Loading…
Cancel
Save