Skip to content

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

Merged
merged 6 commits into from
Jan 8, 2023
Merged

refactor: convert to TypeScript #7

merged 6 commits into from
Jan 8, 2023

Conversation

azu
Copy link
Member

@azu azu commented Jan 8, 2023

Breaking Changes

  • Add SourceRange, SourcePosition, SourceLocation as types
  • Remove SourceLocation and SourcePosition class. It becomes just object
  • Make source.indice private

Features

  • Support TypeScript
    • You can remove @types/structured-source

fix #5

azu added 4 commits January 8, 2023 19:20
- 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";
Copy link
Member Author

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.

Comment on lines -34 to 36
export class SourceLocation {
constructor(start, end) {
this.start = start;
this.end = end;
}
export type SourceLocation = {
readonly end: SourcePosition,
readonly start: SourcePosition,
}
Copy link
Member Author

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.

Copy link
Member Author

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[];
Copy link
Member Author

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.

@azu azu added the Type: Breaking Change Includes breaking changes label Jan 8, 2023
@azu azu added the Type: Feature New Feature label Jan 8, 2023
@azu azu merged commit 868c449 into master Jan 8, 2023
@azu azu deleted the feature/4 branch January 8, 2023 10:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Breaking Change Includes breaking changes Type: Feature New Feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Convert to TypeScript
1 participant