mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-23 11:41:45 +00:00
Implement function types / indirect calls / trampolines (#39)
This commit is contained in:
@ -35,15 +35,18 @@ export class Formatter extends AbstractFormatter {
|
||||
} else {
|
||||
var message = this.lastSeverity ? "\n" : "";
|
||||
switch (this.lastSeverity = failure.getRuleSeverity()) {
|
||||
case "warning":
|
||||
case "warning": {
|
||||
message += colorYellow + "WARNING:" + colorReset;
|
||||
break;
|
||||
case "error":
|
||||
}
|
||||
case "error": {
|
||||
message += colorRed + "ERROR:" + colorReset;
|
||||
break;
|
||||
default:
|
||||
}
|
||||
default: {
|
||||
message += failure.getRuleSeverity();
|
||||
break;
|
||||
}
|
||||
}
|
||||
this.lastFailure = failureString;
|
||||
return message + " " + failureString + " [" + ruleName + "]\n in " + fileName + positionTuple;
|
||||
|
@ -12,6 +12,7 @@ export class Rule extends Lint.Rules.AbstractRule {
|
||||
}
|
||||
|
||||
class DiagnosticsWalker extends Lint.RuleWalker {
|
||||
|
||||
visitVariableDeclaration(node: ts.VariableDeclaration) {
|
||||
if (
|
||||
!node.type && !node.initializer &&
|
||||
@ -20,16 +21,19 @@ class DiagnosticsWalker extends Lint.RuleWalker {
|
||||
this.addFailureAtNode(node, Rule.MISSING_TYPE_OR_INITIALIZER);
|
||||
}
|
||||
}
|
||||
|
||||
visitPropertyDeclaration(node: ts.PropertyDeclaration) {
|
||||
if (!node.type && !node.initializer) {
|
||||
this.addFailureAtNode(node, Rule.MISSING_TYPE_OR_INITIALIZER);
|
||||
}
|
||||
}
|
||||
|
||||
visitParameterDeclaration(node: ts.ParameterDeclaration) {
|
||||
if (!node.type && !node.initializer) {
|
||||
this.addFailureAtNode(node, Rule.MISSING_TYPE_OR_INITIALIZER);
|
||||
}
|
||||
}
|
||||
|
||||
visitFunctionDeclaration(node: ts.FunctionDeclaration) {
|
||||
if (!node.type) {
|
||||
this.addFailureAtNode(node, Rule.MISSING_RETURN_TYPE);
|
||||
|
56
lib/tslint/internal/asInternalCaseRule.js
Normal file
56
lib/tslint/internal/asInternalCaseRule.js
Normal file
@ -0,0 +1,56 @@
|
||||
"use strict";
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
||||
return function (d, b) {
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
exports.__esModule = true;
|
||||
var ts = require("typescript");
|
||||
var Lint = require("tslint");
|
||||
var tsutils_1 = require("tsutils");
|
||||
var Rule = /** @class */ (function (_super) {
|
||||
__extends(Rule, _super);
|
||||
function Rule() {
|
||||
return _super !== null && _super.apply(this, arguments) || this;
|
||||
}
|
||||
Rule.prototype.apply = function (sourceFile) {
|
||||
return this.applyWithWalker(new DiagnosticsWalker(sourceFile, this.getOptions()));
|
||||
};
|
||||
Rule.NOT_BRACED = "Multi-line case clauses should be braced.";
|
||||
return Rule;
|
||||
}(Lint.Rules.AbstractRule));
|
||||
exports.Rule = Rule;
|
||||
var DiagnosticsWalker = /** @class */ (function (_super) {
|
||||
__extends(DiagnosticsWalker, _super);
|
||||
function DiagnosticsWalker() {
|
||||
return _super !== null && _super.apply(this, arguments) || this;
|
||||
}
|
||||
DiagnosticsWalker.prototype.visitDefaultClause = function (node) {
|
||||
this.checkDefaultOrCaseClause(node);
|
||||
_super.prototype.visitDefaultClause.call(this, node);
|
||||
};
|
||||
DiagnosticsWalker.prototype.visitCaseClause = function (node) {
|
||||
this.checkDefaultOrCaseClause(node);
|
||||
_super.prototype.visitCaseClause.call(this, node);
|
||||
};
|
||||
DiagnosticsWalker.prototype.checkDefaultOrCaseClause = function (node) {
|
||||
var count = node.statements.length;
|
||||
if (count > 1) {
|
||||
this.addFailureAtNode(node, Rule.NOT_BRACED);
|
||||
}
|
||||
else if (count == 1) {
|
||||
var stmt = node.statements[0];
|
||||
if (stmt.kind != ts.SyntaxKind.Block) {
|
||||
if (!tsutils_1.isSameLine(node.getSourceFile(), node.getStart(), stmt.getStart())) {
|
||||
this.addFailureAtNode(node, Rule.NOT_BRACED);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
return DiagnosticsWalker;
|
||||
}(Lint.RuleWalker));
|
39
lib/tslint/internal/asInternalCaseRule.ts
Normal file
39
lib/tslint/internal/asInternalCaseRule.ts
Normal file
@ -0,0 +1,39 @@
|
||||
import * as ts from "typescript";
|
||||
import * as Lint from "tslint";
|
||||
import { isSameLine } from "tsutils";
|
||||
|
||||
export class Rule extends Lint.Rules.AbstractRule {
|
||||
|
||||
static NOT_BRACED = "Multi-line case clauses should be braced.";
|
||||
|
||||
apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
|
||||
return this.applyWithWalker(new DiagnosticsWalker(sourceFile, this.getOptions()));
|
||||
}
|
||||
}
|
||||
|
||||
class DiagnosticsWalker extends Lint.RuleWalker {
|
||||
|
||||
visitDefaultClause(node: ts.DefaultClause) {
|
||||
this.checkDefaultOrCaseClause(node);
|
||||
super.visitDefaultClause(node);
|
||||
}
|
||||
|
||||
visitCaseClause(node: ts.CaseClause) {
|
||||
this.checkDefaultOrCaseClause(node);
|
||||
super.visitCaseClause(node);
|
||||
}
|
||||
|
||||
private checkDefaultOrCaseClause(node: ts.DefaultClause | ts.CaseClause) {
|
||||
var count = node.statements.length;
|
||||
if (count > 1) {
|
||||
this.addFailureAtNode(node, Rule.NOT_BRACED);
|
||||
} else if (count == 1) {
|
||||
let stmt = node.statements[0];
|
||||
if (stmt.kind != ts.SyntaxKind.Block) {
|
||||
if (!isSameLine(node.getSourceFile(), node.getStart(), stmt.getStart())) {
|
||||
this.addFailureAtNode(node, Rule.NOT_BRACED);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -12,6 +12,7 @@ export class Rule extends Lint.Rules.AbstractRule {
|
||||
}
|
||||
|
||||
class DiagnosticsWalker extends Lint.RuleWalker {
|
||||
|
||||
visitPropertyAccessExpression(node: ts.PropertyAccessExpression) {
|
||||
if (node.expression.kind === ts.SyntaxKind.Identifier) {
|
||||
if (
|
Reference in New Issue
Block a user