Skip to content

Commit

Permalink
work with both esm and debug settings enabled.
Browse files Browse the repository at this point in the history
  • Loading branch information
botandrose-machine committed Mar 26, 2023
1 parent 16d7a56 commit 852c0ec
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
8 changes: 3 additions & 5 deletions lib/elm/compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,10 @@ def elm_make(elm_path, elm_files, output_path, debug, esm)

def convert_file_to_esm!(path)
contents = File.read(path)
exports = contents[/^\s*_Platform_export\((.*)\)\;\n?\}\(this\)\)\;/, 1]
contents.gsub!(/\(function\s*\(scope\)\s*\{$/, '// -- \1')
exports = contents[/^\s*_Platform_export\((.*)\)\;\n?\}\(this\)\)\;/m, 1]
contents.gsub!(/\(function\s*\(scope\)\s*\{$/m, '// -- \1')
contents.gsub!(/['"]use strict['"];$/, '// -- \1')
contents.gsub!(/function _Platform_export(.*?)\}\n/, '/*\n\1\n*/')
contents.gsub!(/function _Platform_mergeExports(.*?)\}\n\s*}/, '/*\n\1\n*/')
contents.gsub!(/^\s*_Platform_export\((.*)\)\;\n?}\(this\)\)\;/, '/*\n\1\n*/')
contents.gsub!(/^\s*_Platform_export\((.*)\)\;\n?\}\(this\)\)\;/m, '/*\n\1\n*/')
contents << "\nexport default #{exports};"
File.write(path, contents)
end
Expand Down
7 changes: 7 additions & 0 deletions spec/elm/compiler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,12 @@
expect(output).to include("export default {")
end
end

context 'esm output and debugger' do
it 'output should be an ES Module' do
output = Elm::Compiler.compile(test_file, esm: true, debug: true)
expect(output).to include("export default {")
end
end
end
end

0 comments on commit 852c0ec

Please sign in to comment.