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

Fix typescript build #41

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
.idea
*.js.map
node_modules
.project
.project
dist
22 changes: 10 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
{
"name": "mutation-summary",
"version": "0.0.0",
"version": "1.0.0",
"description": "Makes observing the DOM fast and easy",
"main": "src/mutation-summary.js",
"main": "dist/mutation-summary.js",
"types": "dist/mutation-summary.d.ts",
"directories": {
"example": "examples",
"test": "tests"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"prepublish": "tsc"
},
"repository": {
"type": "git",
Expand All @@ -18,13 +19,10 @@
"license": "Apache 2.0",
"devDependencies": {
"chai": "*",
"mocha": "*"
}
"mocha": "*",
"typescript": "^3.7.2"
},
"files": [
"dist"
]
}







19 changes: 10 additions & 9 deletions src/mutation-summary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ class MutationProjection {

this.processChildlistChanges();

var parentNode = node.parentNode;
var parentNode = node.parentNode as Node;
var nodeChange = this.treeChanges.get(node);
if (nodeChange && nodeChange.oldParentNode)
parentNode = nodeChange.oldParentNode;
Expand Down Expand Up @@ -487,7 +487,7 @@ class MutationProjection {
}

getOldPreviousSibling(node:Node):Node {
var parentNode = node.parentNode;
var parentNode = node.parentNode as Node;
var nodeChange = this.treeChanges.get(node);
if (nodeChange && nodeChange.oldParentNode)
parentNode = nodeChange.oldParentNode;
Expand Down Expand Up @@ -613,7 +613,7 @@ class MutationProjection {
return result;
}

matchabilityChange(node:Node) {
matchabilityChange(node:Node): Movement {
// TODO(rafaelw): Include PI, CDATA?
// Only include text nodes.
if (this.characterDataOnly) {
Expand Down Expand Up @@ -697,7 +697,7 @@ class MutationProjection {

var oldPrevious = mutation.previousSibling;

function recordOldPrevious(node:Node, previous:Node) {
const recordOldPrevious = (node:Node, previous:Node) => {
if (!node ||
change.oldPrevious.has(node) ||
change.added.has(node) ||
Expand Down Expand Up @@ -746,7 +746,7 @@ class MutationProjection {

this.processChildlistChanges();

var parentNode = node.parentNode;
var parentNode = node.parentNode as Node;
var nodeChange = this.treeChanges.get(node);
if (nodeChange && nodeChange.oldParentNode)
parentNode = nodeChange.oldParentNode;
Expand Down Expand Up @@ -825,7 +825,7 @@ class MutationProjection {
}
}

class Summary {
export class Summary {
public added:Node[];
public removed:Node[];
public reparented:Node[];
Expand Down Expand Up @@ -940,6 +940,7 @@ class Qualifier {
if ('attrValue' in this)
return '[' + this.attrName + '=' + escapeQuotes(this.attrValue) + ']';

//@ts-ignore
return '[' + this.attrName + ']';
}
}
Expand Down Expand Up @@ -1443,7 +1444,7 @@ function elementFilterAttributes(selectors:Selector[]):string[] {
return Object.keys(attributes);
}

interface Query {
export interface Query {
element?:string;
attribute?:string;
all?:boolean;
Expand All @@ -1453,15 +1454,15 @@ interface Query {
elementFilter?:Selector[];
}

interface Options {
export interface Options {
callback:(summaries:Summary[]) => any;
queries: Query[];
rootNode?:Node;
oldPreviousSibling?:boolean;
observeOwnChanges?:boolean;
}

class MutationSummary {
export class MutationSummary {

public static NodeMap = NodeMap; // exposed for use in TreeMirror.
public static parseElementFilter = Selector.parseSelectors; // exposed for testing.
Expand Down
4 changes: 2 additions & 2 deletions tests/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ suite('Mutation Summary', function() {
});

test('Attribute -- Array proto changed', function() {
Array.prototype.foo = 'bar';
(Array.prototype as any).foo = 'bar';

var div = document.createElement('div');
testDiv.appendChild(div);
Expand Down Expand Up @@ -259,7 +259,7 @@ suite('Mutation Summary', function() {
div2.removeAttribute('foo');
div2.setAttribute('foo', 'baz2');
assertNothingReported();
delete Array.prototype.foo;
delete (Array.prototype as any).foo;
});

test('Attribute Case Insensitive', function() {
Expand Down
16 changes: 16 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"declaration": true,
"outDir": "dist",
"strict": false,
"baseUrl": "./src",
"typeRoots": [ "typings" ],
"esModuleInterop": true,
},
"include": [
"src/**/*.ts",
"typings/*.ts"
]
}
10 changes: 10 additions & 0 deletions typings/extensions.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
declare global {
var WebKitMutationObserver: {
prototype: MutationObserver;
new(callback: MutationCallback): MutationObserver;
};

type WebKitMutationObserver = MutationObserver;
}

export { };
2 changes: 1 addition & 1 deletion util/tree-mirror.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ class TreeMirrorClient {

var self = this;

var queries = [{ all: true }];
var queries = [{ all: true }] as Query[];

if (testingQueries)
queries = queries.concat(testingQueries);
Expand Down