Skip to content
This repository has been archived by the owner on Mar 29, 2018. It is now read-only.

Commit

Permalink
Name based on relative paths in AMD transpiling
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasboyt committed Jun 4, 2013
1 parent 75b78f8 commit 21d4efb
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/amd_compiler.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 48 additions & 0 deletions spec/amd_compiler_spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,51 @@ describe 'Compiler (toAMD)', ->
import { buzz } from "buzz"; */
});
"""

it 'names modules and modifies import statements if a relative path is defined', ->
shouldRunCLI ['--to', 'out', 'lib'],
'lib':
contents: ['foo', 'foo.js']
'lib/foo':
contents: ['bar.js', 'baz.js']
'lib/foo.js':
read: """
import "./foo/bar" as bar;
"""
'lib/foo/bar.js':
read: """
import "./baz" as baz;
"""
'lib/foo/baz.js':
read: ""
'out':
exists: yes
'out/lib':
exists: yes
'out/lib/foo':
exists: yes
'out/lib/foo.js':
write: """
define("lib/foo",
["lib/foo/bar"],
function(bar) {
"use strict";
});
"""
'out/lib/foo/bar.js':
write: """
define("lib/foo/bar",
["lib/foo/baz"],
function(baz) {
"use strict";
});
"""
'out/lib/foo/baz.js':
write: """
define("lib/foo/baz",
[],
function() {
"use strict";
});
"""
8 changes: 8 additions & 0 deletions src/amd_compiler.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import './abstract_compiler' as AbstractCompiler
import { isEmpty } from './utils'
import 'path' as path;

class AMDCompiler extends AbstractCompiler
stringify: ->
Expand All @@ -10,6 +11,13 @@ class AMDCompiler extends AbstractCompiler
@dependencyNames.push 'exports'
wrapperArgs.push '__exports__'

for i of @dependencyNames
dependency = @dependencyNames[i]
if /^\./.test(dependency)
# '..' makes up for path.join() treating a module name w/ no extension
# as a folder
@dependencyNames[i] = path.join(@moduleName, '..', dependency)

s.line =>
s.call 'define', (arg) =>
arg s.print(@moduleName) if @moduleName
Expand Down

0 comments on commit 21d4efb

Please sign in to comment.