Skip to content

Ban import=require and export= under erasableSyntaxOnly - #61175

Merged
Jake Bailey (jakebailey) merged 2 commits into
microsoft:mainfrom
jakebailey:erasable-syntax-only-cjs
Feb 14, 2025
Merged

Ban import=require and export= under erasableSyntaxOnly#61175
Jake Bailey (jakebailey) merged 2 commits into
microsoft:mainfrom
jakebailey:erasable-syntax-only-cjs

Conversation

@jakebailey

@jakebailey Jake Bailey (jakebailey) commented Feb 14, 2025

Copy link
Copy Markdown
Member

Per discussion; this syntax isn't supported by Node.js/Amaro or ts-blank-space, and export= is not actually erasable as its transformed syntax is module.exports=.

This effectively means you can't write any CJS code under erasableSyntaxOnly (without using const foo = require("foo") and module.exports = ... directly, which do not bind in TS). Perhaps we can make const foo = require("...") and module.exports = ... bind like they do in JS for TS files in the future.

Updates #59601
Updates #61011

return MyClassOk;
}());
//// [commonjs.cjs]
"use strict";

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Oh no, this means that CJS isn't even erasable because we assume strict and always insert it

@jakebailey
Jake Bailey (jakebailey) merged commit 0f4737e into microsoft:main Feb 14, 2025
@jakebailey

Copy link
Copy Markdown
Member Author

TypeScript Bot (@typescript-bot) cherry-pick this to release-5.8

@typescript-bot

TypeScript Bot (typescript-bot) commented Feb 14, 2025

Copy link
Copy Markdown
Contributor

Starting jobs; this comment will be updated as builds start and complete.

Command Status Results
cherry-pick this to release-5.8 ✅ Started ✅ Results

@typescript-bot

Copy link
Copy Markdown
Contributor

Hey, Jake Bailey (@jakebailey)! I've created #61178 for you.

@gkiely

Copy link
Copy Markdown

@jakebailey

Copy link
Copy Markdown
Member Author

No, definitely not. I forgot that default exports and export= are the same node.

@jakebailey

Copy link
Copy Markdown
Member Author

Fix in #61210.

@jakebailey

Copy link
Copy Markdown
Member Author

Merged, so should be fixed in the next nightly. I'm glad at least one person is testing them...

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

Labels

Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants