-
-
Notifications
You must be signed in to change notification settings - Fork 3
refactor: convert to TypeScript #7
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
Conversation
- Add SourceRange, SourcePosition, SourceLocation as types - Remove SourceLocation and SourcePosition class. It becomes just object - Make `source.indice` private
README.md
Outdated
const StructuredSource = require('structured-source'); | ||
import { StructuredSource } from "structured-source"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is Breaking Change.
User need to use named import.
- import StructuredSource from "structured-source";
+ import { StructuredSource } from "structured-source";
This will improve compatibility between transpiler and native ESM.
export class SourceLocation { | ||
constructor(start, end) { | ||
this.start = start; | ||
this.end = end; | ||
} | ||
export type SourceLocation = { | ||
readonly end: SourcePosition, | ||
readonly start: SourcePosition, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously, SourceLocation
was Class.
However, I read tests and these test treat SourceLocation
as JSON.
I think that we can represent SourceLocation
as types.
So, I change SourceLocation
class to SourceLocation
type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previous implementaion fail next test.
const src = new StructuredSource('');
assert.deepStrictEqual(src.locationToRange({ // strict equal does not equal JSON and Class
start: { line: 1, column: 0 },
end: { line: 1, column: 2 }
}), [0, 2]);
*/ | ||
export default class StructuredSource { | ||
export class StructuredSource { | ||
private readonly indice: number[]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make indice
private.
Probably, this property is not useful. It is for testing.
Breaking Changes
SourceRange
,SourcePosition
,SourceLocation
as typesSourceLocation
andSourcePosition
class. It becomes just objectsource.indice
privateFeatures
@types/structured-source
fix #5