Skip to content

Commit

Permalink
Merge pull request #48 from khaitu/mangle-properties-global-fix
Browse files Browse the repository at this point in the history
Mangle Properties Fix
  • Loading branch information
ahorek authored Nov 27, 2023
2 parents 636421c + 21c41bd commit 6888b3f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 42 deletions.
2 changes: 2 additions & 0 deletions lib/terser_wrapper.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Set source-map.js sourceMap to terser.js MOZ_SourceMap
MOZ_SourceMap = sourceMap;

var global = global || {};

function comments(option) {
if (Object.prototype.toString.call(option) === '[object Array]') {
return new RegExp(option[0], option[1]);
Expand Down
83 changes: 41 additions & 42 deletions spec/terser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,48 +46,47 @@
expect(Terser.new.compile('var foo="\0bar"')).to include("\\0bar")
end

# TODO: fixme
# describe "property name mangling" do
# let(:source) do
# <<-JS
# var obj = {
# _hidden: false,
# "quoted": 'value'
# };
#
# alert(object.quoted);
# JS
# end
#
# it "does not mangle property names by default" do
# expect(Terser.compile(source)).to include("object.quoted")
# end
#
# it "can be configured to mangle properties" do
# expect(Terser.compile(source, :mangle => { :properties => true }))
# .not_to include("object.quoted")
# end
#
# it "can be configured using old mangle_properties" do
# expect(Terser.compile(source, :mangle_properties => true))
# .not_to include("object.quoted")
# end
#
# it "can configure a regex for mangling" do
# expect(Terser.compile(source, :mangle => { :properties => { :regex => /^_/ } }))
# .to include("object.quoted")
# end
#
# it "can be configured to keep quoted properties" do
# expect(Terser.compile(source, :mangle => { :properties => { :keep_quoted => true } }))
# .to include("object.quoted")
# end
#
# it "can be configured to include debug in mangled properties" do
# expect(Terser.compile(source, :mangle => { :properties => { :debug => true } }))
# .to include("_$quoted$_")
# end
# end
describe "property name mangling" do
let(:source) do
<<-JS
var obj = {
_hidden: false,
"quoted": 'value'
};
alert(object.quoted);
JS
end

it "does not mangle property names by default" do
expect(Terser.compile(source)).to include("object.quoted")
end

it "can be configured to mangle properties" do
expect(Terser.compile(source, :mangle => { :properties => true }))
.not_to include("object.quoted")
end

it "can be configured using old mangle_properties" do
expect(Terser.compile(source, :mangle_properties => true))
.not_to include("object.quoted")
end

it "can configure a regex for mangling" do
expect(Terser.compile(source, :mangle => { :properties => { :regex => /^_/ } }))
.to include("object.quoted")
end

it "can be configured to keep quoted properties" do
expect(Terser.compile(source, :mangle => { :properties => { :keep_quoted => true } }))
.to include("object.quoted")
end

it "can be configured to include debug in mangled properties" do
expect(Terser.compile(source, :mangle => { :properties => { :debug => true } }))
.to include("_$quoted$_")
end
end

describe "argument name mangling" do
let(:code) { "function bar(foo) {return foo + 'bar'};" }
Expand Down

0 comments on commit 6888b3f

Please sign in to comment.