Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

slimdom 2.0 #28

Merged
merged 34 commits into from
Jun 21, 2017
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
90d1f62
Align implementation with current DOM spec.
bwrrp May 18, 2017
7063b74
Add type checks and coercions to match WebIDL specs.
bwrrp May 26, 2017
3ec0c22
Export all public types.
bwrrp May 31, 2017
5623c2e
Create a separate DOMImplementation per Document.
bwrrp May 31, 2017
852afc9
Use correct error codes for errors thrown.
bwrrp May 31, 2017
8e9be09
Implement name validation.
bwrrp May 31, 2017
260c063
Implement DOMImplementation#createHTMLDocument.
bwrrp May 29, 2017
bc83c6c
Fix ownerElement for cloned Attr.
bwrrp May 30, 2017
1b18429
Fix hierarchy check when replacing a doctype.
bwrrp May 30, 2017
4fccece
Implement DocumentFragment.
bwrrp May 30, 2017
366380f
Remove bower.json.
bwrrp Jun 1, 2017
a2a7499
Run web platform DOM tests.
bwrrp May 26, 2017
86c5163
Format code using prettier.
bwrrp Jun 13, 2017
5c63b72
Implement global object to make constructors follow the spec.
bwrrp Jun 14, 2017
6e61080
Implement Node's namespace / prefix lookup methods.
bwrrp Jun 15, 2017
48e85e6
Determine coverage using nyc.
bwrrp Jun 16, 2017
07f73a8
Swap tsconfig files to restore type checking in the editor for tests.
bwrrp Jun 19, 2017
db142c2
Implement CharacterData#previousElementSibling / nextElementSibling.
bwrrp Jun 19, 2017
4937d69
Remove dead code.
bwrrp Jun 19, 2017
f67b875
Add arity checks to Document and Element methods.
bwrrp Jun 19, 2017
79f56fa
Fix error in Range#intersectsNode.
bwrrp Jun 19, 2017
7c29689
Export MutationRecord.
bwrrp Jun 19, 2017
7012d64
Cleanup comments.
bwrrp Jun 19, 2017
042c942
Fix pre-insertion checks to support CDATASection.
bwrrp Jun 19, 2017
80cce37
Mark unreachable branches to be ignored for code coverage.
bwrrp Jun 19, 2017
ad11d3f
Extend test suite for better coverage.
bwrrp Jun 19, 2017
6f4ce21
Make type error messages work with minified code.
bwrrp Jun 19, 2017
f70fc92
Add type checks for remaining public methods.
bwrrp Jun 19, 2017
89d3f84
Add work-around for WebIDLParser.js script alias.
bwrrp Jun 19, 2017
e913e92
Normalize Windows paths to slashes for blacklist check.
bwrrp Jun 19, 2017
7eb5a1c
Bump version.
bwrrp Jun 20, 2017
710d26a
Use mangle blacklist to preserve class names for public types.
bwrrp Jun 21, 2017
54a2d0d
Add test for the DocumentFragment constructor.
bwrrp Jun 21, 2017
ff206ef
Add some content to the README.
bwrrp Jun 21, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Place your settings in this file to overwrite default and user settings.
{
"prettier.printWidth": 120,
"prettier.singleQuote": true,
"prettier.useTabs": true
}
27 changes: 0 additions & 27 deletions bower.json

This file was deleted.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"build:bundle": "rimraf dist && rimraf lib && tsc && rollup -c",
"docs": "typedoc --out docs --excludePrivate --excludeNotExported src/index.ts",
"prepare": "npm run build:bundle",
"test": "rimraf test/bin && tsc -P test && mocha --recursive test/bin/test"
"test": "rimraf test/bin && tsc -P test && mocha --timeout 20000 --recursive test/bin/test"
},
"files": [
"dist"
Expand All @@ -33,6 +33,8 @@
"chai": "^3.5.0",
"lolex": "^1.6.0",
"mocha": "^3.3.0",
"parse5": "^3.0.2",
"prettier": "^1.4.4",
"rimraf": "^2.6.1",
"rollup": "^0.41.6",
"rollup-plugin-babili": "^3.0.0",
Expand Down
35 changes: 20 additions & 15 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,23 @@ import babili from 'rollup-plugin-babili';
const { main: MAIN_DEST_FILE, module: MODULE_DEST_FILE } = require('./package.json');

export default {
entry: 'lib/index.js',
targets: [
{ dest: MAIN_DEST_FILE, format: 'umd' },
{ dest: MODULE_DEST_FILE, format: 'es' },
],
moduleName: 'slimdom',
exports: 'default',
sourceMap: true,
plugins: [
babili({
comments: false,
sourceMap: true
})
]
}
entry: 'lib/index.js',
targets: [{ dest: MAIN_DEST_FILE, format: 'umd' }, { dest: MODULE_DEST_FILE, format: 'es' }],
moduleName: 'slimdom',
exports: 'named',
sourceMap: true,
onwarn(warning) {
// Ignore "this is undefined" warning triggered by typescript's __extends helper
if (warning.code === 'THIS_IS_UNDEFINED') {
return;
}

console.error(warning.message);
},
plugins: [
babili({
comments: false,
sourceMap: true
})
]
};
113 changes: 113 additions & 0 deletions src/Attr.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import Document from './Document';
import Element from './Element';
import Node from './Node';
import { getContext } from './context/Context';
import { changeAttribute } from './util/attrMutations';
import { NodeType } from './util/NodeType';

/**
* 3.9.2. Interface Attr
*/
export default class Attr extends Node {
// Node

public get nodeType(): number {
return NodeType.ATTRIBUTE_NODE;
}

public get nodeName(): string {
// Return the qualified name
return this.name;
}

public get nodeValue(): string | null {
return this._value;
}

public set nodeValue(newValue: string | null) {
// if the new value is null, act as if it was the empty string instead
if (newValue === null) {
newValue = '';
}

// Set an existing attribute value with context object and new value.
setExistingAttributeValue(this, newValue);
}

// Attr

public readonly namespaceURI: string | null;
public readonly prefix: string | null;
public readonly localName: string;
public readonly name: string;

private _value: string;

public get value(): string {
return this._value;
}

public set value(value: string) {
setExistingAttributeValue(this, value);
}

public ownerElement: Element | null;

/**
* (non-standard) use Document#createAttribute(NS) or Element#setAttribute(NS) to create attribute nodes
*
* @param namespace The namespace URI for the attribute
* @param prefix The prefix for the attribute
* @param localName The local name for the attribute
* @param value The value for the attribute
* @param element The element for the attribute, or null if the attribute is not attached to an element
*/
constructor(
namespace: string | null,
prefix: string | null,
localName: string,
value: string,
element: Element | null
) {
super();

this.namespaceURI = namespace;
this.prefix = prefix;
this.localName = localName;
this.name = prefix === null ? localName : `${prefix}:${localName}`;
this._value = value;
this.ownerElement = element;
}

/**
* (non-standard) Creates a copy of the context object, not including its children.
*
* @param document The node document to associate with the copy
*
* @return A shallow copy of the context object
*/
public _copy(document: Document): Attr {
// Set copy’s namespace, namespace prefix, local name, and value, to those of node.
const context = getContext(document);
const copy = new context.Attr(this.namespaceURI, this.prefix, this.localName, this.value, null);
copy.ownerDocument = document;
return copy;
}
}

/**
* To set an existing attribute value, given an attribute attribute and string value, run these steps:
*
* @param attribute The attribute to set the value of
* @param value The new value for attribute
*/
function setExistingAttributeValue(attribute: Attr, value: string) {
// 1. If attribute’s element is null, then set attribute’s value to value.
const element = attribute.ownerElement;
if (element === null) {
(attribute as any)._value = value;
} else {
// 2. Otherwise, change attribute from attribute’s element to value.
changeAttribute(attribute, element, value);
}
}
42 changes: 42 additions & 0 deletions src/CDATASection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import Document from './Document';
import Text from './Text';
import { getContext } from './context/Context';
import { NodeType } from './util/NodeType';

export default class CDATASection extends Text {
// Node

public get nodeType(): number {
return NodeType.CDATA_SECTION_NODE;
}

public get nodeName(): string {
return '#cdata-section';
}

// CDATASection

/**
* (non-standard) use Document#createCDATASection to create a CDATA section.
*
* @param data The data for the node
*/
constructor(data: string) {
super(data);
}

/**
* (non-standard) Creates a copy of the context object, not including its children.
*
* @param document The node document to associate with the copy
*
* @return A shallow copy of the context object
*/
public _copy(document: Document): CDATASection {
// Set copy’s data, to that of node.
const context = getContext(document);
const copy = new context.CDATASection(this.data);
copy.ownerDocument = document;
return copy;
}
}
Loading