Skip to content

Commit

Permalink
Format code using prettier.
Browse files Browse the repository at this point in the history
  • Loading branch information
bwrrp committed Jun 14, 2017
1 parent a2a7499 commit 86c5163
Show file tree
Hide file tree
Showing 41 changed files with 581 additions and 510 deletions.
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
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"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
9 changes: 3 additions & 6 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@ const { main: MAIN_DEST_FILE, module: MODULE_DEST_FILE } = require('./package.js

export default {
entry: 'lib/index.js',
targets: [
{ dest: MAIN_DEST_FILE, format: 'umd' },
{ dest: MODULE_DEST_FILE, format: 'es' },
],
targets: [{ dest: MAIN_DEST_FILE, format: 'umd' }, { dest: MODULE_DEST_FILE, format: 'es' }],
moduleName: 'slimdom',
exports: 'named',
sourceMap: true,
onwarn (warning) {
onwarn(warning) {
// Ignore "this is undefined" warning triggered by typescript's __extends helper
if (warning.code === 'THIS_IS_UNDEFINED') {
return;
Expand All @@ -25,4 +22,4 @@ export default {
sourceMap: true
})
]
}
};
30 changes: 18 additions & 12 deletions src/Attr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ import { NodeType } from './util/NodeType';
export default class Attr extends Node {
// Node

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

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

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

public set nodeValue (newValue: string | null) {
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 = '';
Expand All @@ -42,11 +42,11 @@ export default class Attr extends Node {

private _value: string;

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

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

Expand All @@ -62,7 +62,14 @@ export default class Attr extends Node {
* @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 (document: Document, namespace: string | null, prefix: string | null, localName: string, value: string, element: Element | null) {
constructor(
document: Document,
namespace: string | null,
prefix: string | null,
localName: string,
value: string,
element: Element | null
) {
super(document);
this.namespaceURI = namespace;
this.prefix = prefix;
Expand All @@ -80,7 +87,7 @@ export default class Attr extends Node {
*
* @return A shallow copy of the context object
*/
public _copy (document: Document): Attr {
public _copy(document: Document): Attr {
// Set copy’s namespace, namespace prefix, local name, and value, to those of node.
return new Attr(document, this.namespaceURI, this.prefix, this.localName, this.value, null);
}
Expand All @@ -92,14 +99,13 @@ export default class Attr extends Node {
* @param attribute The attribute to set the value of
* @param value The new value for attribute
*/
function setExistingAttributeValue (attribute: Attr, value: string) {
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;
}
// 2. Otherwise, change attribute from attribute’s element to value.
else {
} else {
// 2. Otherwise, change attribute from attribute’s element to value.
changeAttribute(attribute, element, value);
}
}
8 changes: 4 additions & 4 deletions src/CDATASection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { NodeType } from './util/NodeType';
export default class CDATASection extends Text {
// Node

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

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

Expand All @@ -21,7 +21,7 @@ export default class CDATASection extends Text {
* @param document (non-standard) The node document to associate with the node
* @param data The data for the node
*/
constructor (document: Document, data: string) {
constructor(document: Document, data: string) {
super(document, data);
}

Expand All @@ -32,7 +32,7 @@ export default class CDATASection extends Text {
*
* @return A shallow copy of the context object
*/
public _copy (document: Document): CDATASection {
public _copy(document: Document): CDATASection {
// Set copy’s data, to that of node.
return new CDATASection(document, this.data);
}
Expand Down
30 changes: 15 additions & 15 deletions src/CharacterData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import { asUnsignedLong, treatNullAsEmptyString } from './util/typeHelpers';
export default abstract class CharacterData extends Node implements NonDocumentTypeChildNode, ChildNode {
// Node

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

public set nodeValue (newValue: string | null) {
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 = '';
Expand All @@ -39,27 +39,27 @@ export default abstract class CharacterData extends Node implements NonDocumentT
*/
protected _data: string;

public get data (): string {
public get data(): string {
return this._data;
}

public set data (newValue: string) {
public set data(newValue: string) {
// [TreatNullAs=EmptyString]
newValue = treatNullAsEmptyString(newValue);

// replace data with node context object, offset 0, count context object’s length, and data new value.
replaceData(this, 0, this.length, newValue);
}

public get length (): number {
public get length(): number {
return this.data.length;
}

/**
* @param document The node document to associate with the node
* @param data The data to associate with the node
*/
protected constructor (document: Document, data: string) {
protected constructor(document: Document, data: string) {
super(document);
this._data = data;
}
Expand All @@ -72,7 +72,7 @@ export default abstract class CharacterData extends Node implements NonDocumentT
*
* @return The specified substring
*/
public substringData (offset: number, count: number): string {
public substringData(offset: number, count: number): string {
expectArity(arguments, 2);
return substringData(this, offset, count);
}
Expand All @@ -82,7 +82,7 @@ export default abstract class CharacterData extends Node implements NonDocumentT
*
* @param data Data to append
*/
public appendData (data: string): void {
public appendData(data: string): void {
expectArity(arguments, 1);
replaceData(this, this.length, 0, data);
}
Expand All @@ -93,7 +93,7 @@ export default abstract class CharacterData extends Node implements NonDocumentT
* @param offset Offset at which to insert
* @param data Data to insert
*/
public insertData (offset: number, data: string): void {
public insertData(offset: number, data: string): void {
expectArity(arguments, 1);
replaceData(this, offset, 0, data);
}
Expand All @@ -104,7 +104,7 @@ export default abstract class CharacterData extends Node implements NonDocumentT
* @param offset Offset at which to delete
* @param count Number of code units to delete
*/
public deleteData (offset: number, count: number): void {
public deleteData(offset: number, count: number): void {
expectArity(arguments, 2);
replaceData(this, offset, count, '');
}
Expand All @@ -116,7 +116,7 @@ export default abstract class CharacterData extends Node implements NonDocumentT
* @param count Number of code units to remove
* @param data Data to insert
*/
public replaceData (offset: number, count: number, data: string): void {
public replaceData(offset: number, count: number, data: string): void {
expectArity(arguments, 3);
replaceData(this, offset, count, data);
}
Expand All @@ -130,7 +130,7 @@ export default abstract class CharacterData extends Node implements NonDocumentT
* @param count The number of code units to replace
* @param data The data to insert in place of the removed data
*/
export function replaceData (node: CharacterData, offset: number, count: number, data: string): void {
export function replaceData(node: CharacterData, offset: number, count: number, data: string): void {
// Match spec data types
offset = asUnsignedLong(offset);
count = asUnsignedLong(count);
Expand All @@ -140,7 +140,7 @@ export function replaceData (node: CharacterData, offset: number, count: number,

// 2. If offset is greater than length, then throw an IndexSizeError.
if (offset > length) {
throwIndexSizeError('can not replace data past the node\'s length');
throwIndexSizeError("can not replace data past the node's length");
}

// 3. If offset plus count is greater than length, then set count to length minus offset.
Expand Down Expand Up @@ -196,7 +196,7 @@ export function replaceData (node: CharacterData, offset: number, count: number,
*
* @return The requested substring
*/
export function substringData (node: CharacterData, offset: number, count: number): string {
export function substringData(node: CharacterData, offset: number, count: number): string {
// Match spec data types
offset = asUnsignedLong(offset);
count = asUnsignedLong(count);
Expand All @@ -206,7 +206,7 @@ export function substringData (node: CharacterData, offset: number, count: numbe

// 2. If offset is greater than length, then throw an IndexSizeError.
if (offset > length) {
throwIndexSizeError('can not substring data past the node\'s length');
throwIndexSizeError("can not substring data past the node's length");
}

// 3. If offset plus count is greater than length, return a string whose value is the code units from the offsetth
Expand Down
8 changes: 4 additions & 4 deletions src/Comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { NodeType } from './util/NodeType';
export default class Comment extends CharacterData {
// Node

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

public get nodeName (): string {
public get nodeName(): string {
return '#comment';
}

Expand All @@ -24,7 +24,7 @@ export default class Comment extends CharacterData {
* @param document (non-standard) The node document to associate with the new comment
* @param data The data for the new comment
*/
constructor (document: Document, data: string = '') {
constructor(document: Document, data: string = '') {
super(document, data);
}

Expand All @@ -35,7 +35,7 @@ export default class Comment extends CharacterData {
*
* @return A shallow copy of the context object
*/
public _copy (document: Document): Comment {
public _copy(document: Document): Comment {
// Set copy’s data, to that of node.
return new Comment(document, this.data);
}
Expand Down
12 changes: 8 additions & 4 deletions src/DOMImplementation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default class DOMImplementation {
*
* @param document The document to associate with this instance
*/
constructor (document: Document) {
constructor(document: Document) {
this._document = document;
}

Expand All @@ -31,7 +31,7 @@ export default class DOMImplementation {
*
* @return The new doctype node
*/
createDocumentType (qualifiedName: string, publicId: string, systemId: string): DocumentType {
createDocumentType(qualifiedName: string, publicId: string, systemId: string): DocumentType {
// 1. Validate qualifiedName.
validateQualifiedName(qualifiedName);

Expand All @@ -50,7 +50,11 @@ export default class DOMImplementation {
*
* @return The new XMLDocument
*/
createDocument (namespace: string | null, qualifiedName: string | null, doctype: DocumentType | null = null): XMLDocument {
createDocument(
namespace: string | null,
qualifiedName: string | null,
doctype: DocumentType | null = null
): XMLDocument {
expectArity(arguments, 2);
namespace = asNullableString(namespace);
// [TreatNullAs=EmptyString] for qualifiedName
Expand Down Expand Up @@ -99,7 +103,7 @@ export default class DOMImplementation {
*
* @return The new document
*/
createHTMLDocument (title?: string | null): Document {
createHTMLDocument(title?: string | null): Document {
title = asNullableString(title);

// 1. Let doc be a new document that is an HTML document.
Expand Down
Loading

0 comments on commit 86c5163

Please sign in to comment.