mirror of https://github.com/sveltejs/svelte
parent
7c86487691
commit
e57ddb0503
@ -0,0 +1,34 @@
|
|||||||
|
import deindent from '../../utils/deindent';
|
||||||
|
import { stringify } from '../../utils/stringify';
|
||||||
|
import Node from './shared/Node';
|
||||||
|
import Block from '../dom/Block';
|
||||||
|
import Attribute from './Attribute';
|
||||||
|
|
||||||
|
const readonly = new Set([
|
||||||
|
'innerWidth',
|
||||||
|
'innerHeight',
|
||||||
|
'outerWidth',
|
||||||
|
'outerHeight',
|
||||||
|
'online',
|
||||||
|
]);
|
||||||
|
|
||||||
|
export default class Document extends Node {
|
||||||
|
type: 'Document';
|
||||||
|
attributes: Attribute[];
|
||||||
|
|
||||||
|
build(
|
||||||
|
block: Block,
|
||||||
|
parentNode: string,
|
||||||
|
parentNodes: string
|
||||||
|
) {
|
||||||
|
const { generator } = this;
|
||||||
|
|
||||||
|
this.var = 'document';
|
||||||
|
|
||||||
|
this.attributes.forEach((attribute: Attribute) => {
|
||||||
|
if (attribute.name === 'title') {
|
||||||
|
attribute.render(block);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,42 @@
|
|||||||
|
import flattenReference from '../../utils/flattenReference';
|
||||||
|
import fuzzymatch from '../utils/fuzzymatch';
|
||||||
|
import list from '../../utils/list';
|
||||||
|
import validateEventHandler from './validateEventHandler';
|
||||||
|
import { Validator } from '../index';
|
||||||
|
import { Node } from '../../interfaces';
|
||||||
|
|
||||||
|
const descriptions = {
|
||||||
|
Bindings: 'two-way bindings',
|
||||||
|
EventHandler: 'event handlers',
|
||||||
|
Transition: 'transitions',
|
||||||
|
Ref: 'refs'
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function validateWindow(validator: Validator, node: Node, refs: Map<string, Node[]>, refCallees: Node[]) {
|
||||||
|
node.attributes.forEach((attribute: Node) => {
|
||||||
|
if (attribute.type === 'Attribute') {
|
||||||
|
if (attribute.name !== 'title') {
|
||||||
|
validator.error(
|
||||||
|
`<:Document> can only have a 'title' attribute`,
|
||||||
|
attribute.start
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
const description = descriptions[attribute.type];
|
||||||
|
if (description) {
|
||||||
|
validator.error(
|
||||||
|
`<:Document> does not support ${description}`,
|
||||||
|
attribute.start
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
// future-proofing
|
||||||
|
validator.error(
|
||||||
|
`<:Document> can only have a 'title' attribute`,
|
||||||
|
attribute.start
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
export default {
|
||||||
|
data: {
|
||||||
|
adjective: 'custom'
|
||||||
|
},
|
||||||
|
|
||||||
|
test(assert, component, target, window) {
|
||||||
|
assert.equal(window.document.title, 'a custom title');
|
||||||
|
|
||||||
|
component.set({ adjective: 'different' });
|
||||||
|
assert.equal(window.document.title, 'a different title');
|
||||||
|
}
|
||||||
|
};
|
@ -0,0 +1 @@
|
|||||||
|
<:Document title='a {{adjective}} title'/>
|
@ -0,0 +1,5 @@
|
|||||||
|
export default {
|
||||||
|
test(assert, component, target, window) {
|
||||||
|
assert.equal(window.document.title, 'changed');
|
||||||
|
}
|
||||||
|
};
|
@ -0,0 +1 @@
|
|||||||
|
<:Document title='changed'/>
|
Loading…
Reference in new issue