Skip to content

feat(transformer/typescript): report error relate mts/cts files#3278

Closed
Dunqing wants to merge 1 commit intomainfrom
05-14-feat_transformer_typescript_report_error_relate_mts_cts_files
Closed

feat(transformer/typescript): report error relate mts/cts files#3278
Dunqing wants to merge 1 commit intomainfrom
05-14-feat_transformer_typescript_report_error_relate_mts_cts_files

Conversation

@Dunqing
Copy link
Member

@Dunqing Dunqing commented May 14, 2024

No description provided.

@graphite-app
Copy link
Contributor

graphite-app bot commented May 14, 2024

Your org has enabled the Graphite merge queue for merging into main

Add the label “merge” to the PR and Graphite will automatically add it to the merge queue when it’s ready to merge. Or use the label “hotfix” to add to the merge queue as a hot fix.

You must have a Graphite account and log in to Graphite in order to use the merge queue. Sign up using this link.

@Dunqing Dunqing marked this pull request as ready for review May 14, 2024 14:24
@github-actions github-actions bot added the A-transformer Area - Transformer / Transpiler label May 14, 2024
Copy link
Member Author

Dunqing commented May 14, 2024

@codspeed-hq
Copy link

codspeed-hq bot commented May 14, 2024

CodSpeed Performance Report

Merging #3278 will not alter performance

Comparing 05-14-feat_transformer_typescript_report_error_relate_mts_cts_files (de0e69d) with main (5b2fc39)

Summary

✅ 27 untouched benchmarks

Base automatically changed from 05-13-fix_transformer_do_no_add___self_when_the_jsx_is_inside_constructor to main May 14, 2024 15:12
@Dunqing Dunqing force-pushed the 05-14-feat_transformer_typescript_report_error_relate_mts_cts_files branch from 9233efa to bf6ad8d Compare May 14, 2024 23:24
@Dunqing Dunqing force-pushed the 05-14-feat_transformer_typescript_report_error_relate_mts_cts_files branch from bf6ad8d to de0e69d Compare May 15, 2024 02:24
@Boshen
Copy link
Member

Boshen commented May 15, 2024

This feels so weird thrown from the transformer, let me double check.

@Boshen
Copy link
Member

Boshen commented May 15, 2024

These are checker errors, we should throw them from the typescript checker.

From checker.ts:

    function checkAssertion(node: AssertionExpression, checkMode: CheckMode | undefined) {
        if (node.kind === SyntaxKind.TypeAssertionExpression) {
            const file = getSourceFileOfNode(node);
            if (file && fileExtensionIsOneOf(file.fileName, [Extension.Cts, Extension.Mts])) {
                grammarErrorOnNode(node, Diagnostics.This_syntax_is_reserved_in_files_with_the_mts_or_cts_extension_Use_an_as_expression_instead);
            }
        }
        return checkAssertionWorker(node, checkMode);
    }
    function checkGrammarArrowFunction(node: Node, file: SourceFile): boolean {
        if (!isArrowFunction(node)) {
            return false;
        }

        if (node.typeParameters && !(length(node.typeParameters) > 1 || node.typeParameters.hasTrailingComma || node.typeParameters[0].constraint)) {
            if (file && fileExtensionIsOneOf(file.fileName, [Extension.Mts, Extension.Cts])) {
                grammarErrorOnNode(node.typeParameters[0], Diagnostics.This_syntax_is_reserved_in_files_with_the_mts_or_cts_extension_Add_a_trailing_comma_or_explicit_constraint);
            }
        }

        const { equalsGreaterThanToken } = node;
        const startLine = getLineAndCharacterOfPosition(file, equalsGreaterThanToken.pos).line;
        const endLine = getLineAndCharacterOfPosition(file, equalsGreaterThanToken.end).line;
        return startLine !== endLine && grammarErrorOnNode(equalsGreaterThanToken, Diagnostics.Line_terminator_not_permitted_before_arrow);
    }

We don't run semantic check in the test suite, I wonder whether we should 😅

Copy link
Member

@Boshen Boshen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The check should be done somewhere else.

@Dunqing
Copy link
Member Author

Dunqing commented May 15, 2024

We don't run semantic check in the test suite, I wonder whether we should 😅

I initially wanted to throw the error in the semantic, but the transformer doesn't need semantic now.

@Boshen
Copy link
Member

Boshen commented May 15, 2024

Let's throw these in semantic checker, and ignore them from the transformer suite because they shouldn't be there ...

@Dunqing
Copy link
Member Author

Dunqing commented May 15, 2024

Let's throw these in semantic checker, and ignore them from the transformer suite because they shouldn't be there ...

The semantic doesn't have a source_path. Should we pass it in?

@Boshen
Copy link
Member

Boshen commented May 15, 2024

source_path

Why do we need source_path?

@Dunqing
Copy link
Member Author

Dunqing commented May 15, 2024

source_path

Why do we need source_path?

These errors only report in files with the .mts or .cts extension

@Boshen
Copy link
Member

Boshen commented May 15, 2024

source_path

Why do we need source_path?

These errors only report in files with the .mts or .cts extension

Oh, the information should be encoded in crates/oxc_span/src/source_type.rs

what are their official names and categories?

@Boshen Boshen closed this May 15, 2024
@Boshen Boshen deleted the 05-14-feat_transformer_typescript_report_error_relate_mts_cts_files branch May 15, 2024 14:14
@Boshen
Copy link
Member

Boshen commented May 15, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-transformer Area - Transformer / Transpiler

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants