@fimbul/mimir
Advanced tools
Comparing version 0.18.0 to 0.19.0-dev.20190111
{ | ||
"name": "@fimbul/mimir", | ||
"version": "0.18.0", | ||
"version": "0.19.0-dev.20190111", | ||
"description": "Core rules of the Fimbullinter project", | ||
@@ -28,3 +28,3 @@ "main": "recommended.yaml", | ||
"dependencies": { | ||
"@fimbul/ymir": "^0.18.0", | ||
"@fimbul/ymir": "0.18.0", | ||
"chalk": "^2.3.2", | ||
@@ -31,0 +31,0 @@ "debug": "^4.0.0", |
@@ -15,2 +15,3 @@ import { TypedRule } from '@fimbul/ymir'; | ||
private matchIntersectionType; | ||
private getTypeOfExpression; | ||
} |
@@ -7,2 +7,3 @@ "use strict"; | ||
const tsutils_1 = require("tsutils"); | ||
const utils_1 = require("../utils"); | ||
const primitiveFlags = ts.TypeFlags.BigIntLike | ts.TypeFlags.BooleanLike | ts.TypeFlags.NumberLike | ts.TypeFlags.StringLike | | ||
@@ -131,3 +132,3 @@ ts.TypeFlags.ESSymbolLike | ts.TypeFlags.Undefined | ts.TypeFlags.Void; | ||
} | ||
return this.executePredicate(this.checker.getTypeAtLocation(node), truthyFalsy); | ||
return this.executePredicate(this.getTypeOfExpression(node), truthyFalsy); | ||
} | ||
@@ -157,3 +158,3 @@ isConstantComparison(left, right, operator) { | ||
else { | ||
let type = this.checker.getTypeAtLocation(right); | ||
let type = this.getTypeOfExpression(right); | ||
type = this.checker.getBaseConstraintOfType(type) || type; | ||
@@ -187,3 +188,3 @@ if ((type.flags & ts.TypeFlags.StringLiteral) === 0) | ||
} | ||
return this.nullAwarePredicate(this.checker.getTypeAtLocation(left), predicate); | ||
return this.nullAwarePredicate(this.getTypeOfExpression(left), predicate); | ||
} | ||
@@ -238,2 +239,24 @@ nullAwarePredicate(type, predicate) { | ||
} | ||
getTypeOfExpression(node) { | ||
const type = this.checker.getTypeAtLocation(node); | ||
if (!this.strictNullChecks) | ||
return type; | ||
if (tsutils_1.unionTypeParts(type).some((t) => (t.flags & ts.TypeFlags.Undefined) !== 0)) | ||
return type; | ||
if (!tsutils_1.isPropertyAccessExpression(node) && !tsutils_1.isElementAccessExpression(node)) | ||
return type; | ||
const objectType = this.checker.getApparentType(this.checker.getTypeAtLocation(node.expression)); | ||
if (objectType.getStringIndexType() === undefined && objectType.getNumberIndexType() === undefined) | ||
return type; | ||
if (tsutils_1.isPropertyAccessExpression(node)) { | ||
if (objectType.getProperty(node.name.text) !== undefined) | ||
return type; | ||
} | ||
else { | ||
const names = utils_1.lateBoundPropertyNames(node.argumentExpression, this.checker); | ||
if (names.known && names.properties.every(({ symbolName }) => utils_1.getPropertyOfType(objectType, symbolName) !== undefined)) | ||
return type; | ||
} | ||
return this.checker.getNullableType(type, ts.TypeFlags.Undefined); | ||
} | ||
}; | ||
@@ -240,0 +263,0 @@ Rule = tslib_1.__decorate([ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
376883
4458
Updated@fimbul/ymir@0.18.0