mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-04 06:47:03 +00:00
Merge pull request #31183 from TeamworkGuy2/master
[syntax-error] Add syntax-error@1.4.0 definition
This commit is contained in:
Vendored
+18
@@ -0,0 +1,18 @@
|
||||
// Type definitions for syntax-error 1.4
|
||||
// Project: https://github.com/browserify/syntax-error
|
||||
// Definitions by: TeamworkGuy2 <https://github.com/TeamworkGuy2>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
import * as acorn from "acorn";
|
||||
|
||||
/**
|
||||
* Check the source code string 'src' for syntax errors. Optionally you can specify a filename
|
||||
* file that will show up in the output.
|
||||
* If 'src' has a syntax error, return an error object err that can be printed or stringified.
|
||||
* If there are no syntax errors in 'src', return undefined.
|
||||
* Options will be passed through to acorn-node. acorn-node defaults to options
|
||||
* that match the most recent Node versions.
|
||||
*/
|
||||
declare function syntaxError(src: any, file?: string, opts?: acorn.Options): (SyntaxError & { line: number; column: number; annotated: string; inspect(): string }) | undefined;
|
||||
|
||||
export = syntaxError;
|
||||
@@ -0,0 +1,12 @@
|
||||
import syntaxError = require("syntax-error");
|
||||
|
||||
function test(): SyntaxError | undefined {
|
||||
const res1 = syntaxError("(function(){ console.log('do something!'); }());", "motivation.js");
|
||||
const res2 = syntaxError("(function(){ console.log('do something!'); }());", "motivation.js", { ecmaVersion: 2015, sourceType: "script" });
|
||||
if (res2 != null) {
|
||||
if (res2.line === 1) {
|
||||
const msg = `${res2.name} (${res2.line}:${Math.abs(res2.column)}): ${res2.message}\n${res2.stack}`;
|
||||
}
|
||||
}
|
||||
return res1 || res2;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"syntax-error-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user