Skip to content

fix: normalize PURE annotations for Vite 8 and Rolldown - #2766

Merged
Hector Hernandez (hectorhdzg) merged 4 commits into
microsoft:mainfrom
hectorhdzg:hectorhdzg-fix-vite8-pure-annotations
Sep 8, 2026
Merged

fix: normalize PURE annotations for Vite 8 and Rolldown#2766
Hector Hernandez (hectorhdzg) merged 4 commits into
microsoft:mainfrom
hectorhdzg:hectorhdzg-fix-vite8-pure-annotations

Conversation

@hectorhdzg

Copy link
Copy Markdown
Member

Fixes invalid PURE annotation warnings emitted by Vite 8/Rolldown when consuming the SDK's dist-es5 modules.

The generated JavaScript is now parsed so that:

  • PURE annotations on call and new expressions are preserved and canonicalized.
  • PURE annotations on literals and other unsupported expressions are removed.
  • Annotation-like text inside strings and ordinary comments remains untouched.
  • Legacy PURE markers remain unchanged in TypeScript source.
  • Both Rollup dist/es5 and TypeScript dist-es5 outputs use the same normalization.

Testing

Added coverage for literals, arrays, objects, functions, classes, regexes, templates, unary/binary/conditional expressions, calls, constructors, IIFEs, optional calls, multiline ESM, comments, strings, idempotency, and invalid JavaScript.

Fixes #2763
Fixes #2764

Rolldown cannot apply PURE annotations to primitive literals and emits INVALID_ANNOTATION warnings when consuming the Vite 8 module build. Remove the invalid markers and extend bundle checks to prevent regressions. Fixes microsoft#2764.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Prefer concise names that describe the change and avoid generic investigation or issue-only branch names.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Honor the prior maintainer direction from microsoft#2737 and microsoft#2744 by retaining parenthesized PURE markers in source. Remove ineffective annotations from primitive literals only when normalizing emitted bundles so Rolldown can consume dist-es5 without warnings.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Parse generated JavaScript so PURE annotations are retained only for call and new expressions. Remove invalid annotations from every other expression without altering strings or ordinary comments, and run comprehensive parser fixtures in CI.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI lite review requested due to automatic review settings September 8, 2026 20:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The new PURE normalization test file contains invalid JS/incorrect expected strings that will fail parsing/assertions, and the new acorn@^8.18.0 dependency likely requires lockfile updates for Rush/pnpm consistency.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR updates the build tooling to normalize /*#__PURE__*/ / /*@__PURE__*/ annotations in generated ES5 module output so newer bundlers (Vite 8 / Rolldown) don’t emit [INVALID_ANNOTATION] warnings, while preserving valid annotations on call/new expressions.

Changes:

  • Replaces regex-based PURE spacing normalization with AST-based parsing (Acorn) to canonicalize valid annotations and remove invalid ones.
  • Adds a dedicated Node test (tools/pureAnnotations.test.mjs) and wires it into npm test.
  • Extends size tests to detect PURE annotations applied to literals (a known invalid form for Rolldown).
File summaries
File Description
tools/pureAnnotations.test.mjs Adds normalization test coverage for many expression types and idempotency.
tools/pureAnnotations.mjs Implements AST-driven PURE annotation normalization using Acorn tokens/comments.
tools/grunt-tasks/fixPureAnnotations.js Updates the Grunt task to use the shared normalizer and handle failures.
shared/AppInsightsCore/Tests/Unit/src/ai/AppInsightsCoreSize.Tests.ts Tightens output validation by detecting PURE-on-literal patterns.
AISKU/Tests/Unit/src/AISKUSize.Tests.ts Same PURE validity checks for AISKU bundle outputs.
package.json Adds test:pure-annotations and the acorn devDependency.
.github/copilot-instructions.md Adds a repository branch naming convention guideline.
Review details

Suppressed comments (4)

tools/pureAnnotations.test.mjs:50

  • These expected strings are missing the opening /* of the PURE comment; canonicalizePureAnnotations() emits /*#__PURE__*/..., so the assertions will fail.
    {
        expected: "var value = /*#__PURE__*/namespace.factory();",
        input: "var value = /* #__PURE__ */ namespace.factory();"
    },

tools/pureAnnotations.test.mjs:54

  • This expected output is missing the opening /* for the PURE comment, so the assertion won't match the normalized output.
    {
        expected: "var value = /*#__PURE__*/(function () {})();",
        input: "var value = /* #__PURE__ */ (function () {})();"
    },

tools/pureAnnotations.test.mjs:58

  • This expected output is missing the opening /* for the PURE comment, so the assertion won't match the normalized output.
    {
        expected: "var value = /*#__PURE__*/(0, factory)();",
        input: "var value = /* #__PURE__ */ (0, factory)();"
    },

tools/grunt-tasks/fixPureAnnotations.js:80

  • The success log still says "Canonicalized" even though the task now removes invalid annotations as well; updating wording to "Normalized" would better reflect what happened.
            grunt.log.ok("Canonicalized PURE annotations: checked " + filesChecked + " file(s), updated " + filesChanged + " file(s).");
  • Files reviewed: 7/7 changed files
  • Comments generated: 3
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread package.json
Comment thread tools/pureAnnotations.test.mjs
Comment thread tools/grunt-tasks/fixPureAnnotations.js
@hectorhdzg
Hector Hernandez (hectorhdzg) merged commit c7267f2 into microsoft:main Sep 8, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

After upgrading to Vue3/Vite 8, Console Warning [INVALID_ANNOTATION] core-js After upgrading to Vue3/Vite 8, Console Warning [INVALID_ANNOTATION]

3 participants