Skip to content

Name mangler should mangle synthesized identifiers #6820

@kdy1

Description

@kdy1

This is follow-up of #6818.
With the PR, the variable renamed is now able to rename even with presence of eval.

But for modification, the current code is not ideal.

For the input

import styled from 'styled-components';

const C1 = styled.div`
  position: absolute;
`;

const C2 = styled.div`
  position: absolute;
`;

const debug = eval('');

swc produces

import _tagged_template_literal from "@swc/helpers/src/_tagged_template_literal.mjs";
function _templateObject() {
    var n = _tagged_template_literal([
        "\n  position: absolute;\n"
    ]);
    _templateObject = function r() {
        return n;
    };
    return n;
}
function _templateObject1() {
    var n = _tagged_template_literal([
        "\n  position: absolute;\n"
    ]);
    _templateObject1 = function r() {
        return n;
    };
    return n;
}
import styled from "styled-components";
var C1 = styled.div(_templateObject());
var C2 = styled.div(_templateObject1());
var debug = eval("");

but there are some synthesized variables.
This is because we apply hygiene before applying the name mangler, and hygiene pass removes information indicating if an identifier is synthesized.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions