Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.
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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: node_js
node_js: '10'
node_js: '12'

notifications:
email: false
Expand Down
44 changes: 0 additions & 44 deletions Gruntfile.coffee

This file was deleted.

4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
image: Visual Studio 2015
image: Visual Studio 2017

environment:
nodejs_version: "6"
nodejs_version: "12"

platform:
- x86
Expand Down
6 changes: 6 additions & 0 deletions babel.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"presets": ["babel-preset-atomic"],
"plugins": [],
"exclude": "node_modules/**",
"sourceMap": "inline"
}
25 changes: 14 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
"description": "Log usage of deprecated methods",
"main": "./lib/grim",
"scripts": {
"prepublish": "grunt clean lint coffee",
"test": "grunt test"
"lint": "coffeelint .",
"test": "npm run build && jasmine-node --coffee --captureExceptions --forceexit spec",
"dev": "npm run build -- --watch",
"build": " babel src --out-dir lib --delete-dir-on-start",
"prepare": "npm run build"
},
"repository": {
"type": "git",
Expand All @@ -24,15 +27,15 @@
"event-kit": "^2.0.0"
},
"devDependencies": {
"coffee-script": "^1.7.0",
"jasmine-focused": "^1.0.4",
"grunt-contrib-coffee": "^0.9.0",
"grunt-cli": "^0.1.8",
"grunt": "^0.4.1",
"grunt-shell": "^0.2.2",
"grunt-coffeelint": "^0.0.6",
"rimraf": "^2.2.2",
"coffee-cache": "^0.2.0",
"babel-preset-atomic": "^4.1.0",
"coffeelint": "^2.1.0",
"jasmine-node": "^3.0.0",
"temp": "^0.6.0"
},
"coffeelintConfig": {
"max_line_length": {
"level": "error",
"value": 120
}
}
}
4 changes: 2 additions & 2 deletions spec/grim-spec.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
grim = require '../src/grim'
Deprecation = require '../src/deprecation'
grim = require '../lib/grim'
Deprecation = require '../lib/deprecation'

describe "Grim", ->
beforeEach ->
Expand Down
1 change: 0 additions & 1 deletion spec/spec-helper.coffee

This file was deleted.

93 changes: 0 additions & 93 deletions src/deprecation.coffee

This file was deleted.

128 changes: 128 additions & 0 deletions src/deprecation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* DS104: Avoid inline assignments
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
const SourceMapCache = {}

export default class Deprecation {
static getFunctionNameFromCallsite(callsite) {}

static deserialize({message, fileName, lineNumber, stacks}) {
const deprecation = new Deprecation(message, fileName, lineNumber);
for (let stack of stacks) { deprecation.addStack(stack, stack.metadata); }
return deprecation;
}

constructor(message, fileName, lineNumber) {
this.message = message;
this.fileName = fileName;
this.lineNumber = lineNumber;
this.callCount = 0;
this.stackCount = 0;
this.stacks = {};
this.stackCallCounts = {};
}

getFunctionNameFromCallsite(callsite) {
if (callsite.functionName != null) { return callsite.functionName; }

if (callsite.isToplevel()) {
let left;
return (left = callsite.getFunctionName()) != null ? left : '<unknown>';
} else {
if (callsite.isConstructor()) {
return `new ${callsite.getFunctionName()}`;
} else if (callsite.getMethodName() && !callsite.getFunctionName()) {
return callsite.getMethodName();
} else {
let left1, left2;
return `${callsite.getTypeName()}.${(left1 = (left2 = callsite.getMethodName()) != null ? left2 : callsite.getFunctionName()) != null ? left1 : '<anonymous>'}`;
}
}
}

getLocationFromCallsite(callsite) {
if (callsite == null) { return "unknown"; }
if (callsite.location != null) { return callsite.location; }

if (callsite.isNative()) {
return "native";
} else if (callsite.isEval()) {
return `eval at ${this.getLocationFromCallsite(callsite.getEvalOrigin())}`;
} else {
const fileName = callsite.getFileName();
const line = callsite.getLineNumber();
const column = callsite.getColumnNumber();
return `${fileName}:${line}:${column}`;
}
}

getFileNameFromCallSite(callsite) {
return callsite.fileName != null ? callsite.fileName : callsite.getFileName();
}

getOriginName() {
return this.originName;
}

getMessage() {
return this.message;
}

getStacks() {
const parsedStacks = [];
for (let location in this.stacks) {
const stack = this.stacks[location];
const parsedStack = this.parseStack(stack);
parsedStack.callCount = this.stackCallCounts[location];
parsedStack.metadata = stack.metadata;
parsedStacks.push(parsedStack);
}
return parsedStacks;
}

getStackCount() {
return this.stackCount;
}

getCallCount() {
return this.callCount;
}

addStack(stack, metadata) {
if (this.originName == null) { this.originName = this.getFunctionNameFromCallsite(stack[0]); }
if (this.fileName == null) { this.fileName = this.getFileNameFromCallSite(stack[0]); }
if (this.lineNumber == null) { this.lineNumber = stack[0].getLineNumber?.(); }
this.callCount++;

stack.metadata = metadata;
const callerLocation = this.getLocationFromCallsite(stack[1]);
if (this.stacks[callerLocation] == null) {
this.stacks[callerLocation] = stack;
this.stackCount++;
}
if (this.stackCallCounts[callerLocation] == null) { this.stackCallCounts[callerLocation] = 0; }
return this.stackCallCounts[callerLocation]++;
}

parseStack(stack) {
return stack.map(callsite => {
return {
functionName: this.getFunctionNameFromCallsite(callsite),
location: this.getLocationFromCallsite(callsite),
fileName: this.getFileNameFromCallSite(callsite)
};
});
}

serialize() {
return {
message: this.getMessage(),
lineNumber: this.lineNumber,
fileName: this.fileName,
stacks: this.getStacks()
};
}
};
Loading