fix(compiler): allow bare side-effect imports of ambient-only modules - #198
Open
techfreaque wants to merge 1 commit into
Open
fix(compiler): allow bare side-effect imports of ambient-only modules#198techfreaque wants to merge 1 commit into
techfreaque wants to merge 1 commit into
Conversation
Contributor
|
@mabr-pcvisit is attempting to deploy a commit to the Vercel Labs Team on Vercel. A member of the Team first needs to authorize it. |
A bare `import "spec";` with no bound names of a module that exists only as an ambient `declare module` type surface has no runtime module and nothing bound from it for other code to observe, so dropping the statement is behaviorally exact. This is the standard shape of a bundler-only stylesheet import (`import "pkg/dist/style.css";`), which previously hard-errored with SC1010 like any other unsupported import. Bound imports of the same kind of module (`import styles from "x.css"`) still fence, since something would be missing.
techfreaque
force-pushed
the
fix-ambient-css-noop
branch
from
August 22, 2026 09:29
0e6d11e to
91ec382
Compare
techfreaque
added a commit
to techfreaque/scriptc
that referenced
this pull request
Aug 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
A bare side-effect import —
import "somepackage/dist/style.css";, withno default, named, or namespace binding — is a no-op in every JS runtime
that isn't asked to bundle CSS, including scriptc's own compiled
binaries (there is no browser to apply a stylesheet side effect to).
When the imported specifier resolves only to an ambient
declare module "*.css"(or similarly-shaped) type surface — i.e. there is a typedeclaration but no compilable runtime module behind it — the preflight
import-statement pass in
packages/compiler/src/frontend/program.tsstill hard-errors on it:
This is a near-universal pattern for any component library that ships
its own stylesheet, and it blocked the containing file from being
analyzed at all.
Root cause
The bare-import case was treated identically to a bound import (
import x from "spec",import { x } from "spec") of the same kind of module.For a bound import that's correct — the program expects a real binding
that doesn't exist. For a bare side-effect import, nothing is bound, so
there is nothing later code could observe being missing.
Fix
In
preflight7(packages/compiler/src/frontend/program.ts), beforethe existing ambient-module fence fires for a bare import specifier that
resolves to types only, add a guard: if the import statement has no
import clause at all (
stmt.importClause === undefined, i.e. a pureimport "spec";) and the specifier is only ambient-declared(
ambientDeclared(spec), an existing helper already used by thisfunction's diagnostic messages), skip the statement instead of fencing
it. Bound imports of the same module still fence exactly as before.
Verification
cd packages/compiler && node node_modules/typescript5/bin/tsc -p tsconfig.json— 0 errors.packages/compiler/test/ts7,tests/harness/diagnostics.test.ts) pass identically before and afterthe change (compared against the unmodified base) — no regressions.
The
tests/diagnostics/pkg-import-fencesfixture, which asserts boundambient-module imports still fence, is unaffected since all its
imports bind names.
analyze()API: adeclare module "*.css";ambient declaration plus a bareimport "foo/dist/style.css";now analyzes with zero diagnostics, while
import styles from "foo/dist/style.css";against the same declaration still produces theSC1010 diagnostic.