Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error from importjs#ImportJSImport command #1

Closed
flarnie opened this issue Nov 28, 2014 · 3 comments
Closed

Error from importjs#ImportJSImport command #1

flarnie opened this issue Nov 28, 2014 · 3 comments
Labels

Comments

@flarnie
Copy link
Contributor

flarnie commented Nov 28, 2014

When I try to use 'importJS' I have been seeing this error:

Error detected while processing /Users/paradasia/.vim/bundle/import-js/autoload/importjs.vim:
line 20:
SyntaxError: (eval):1:in require': /Users/paradasia/.vim/bundle/import-js/ruby/import-js/importer.rb:71: syntax error, unexpected '.', expecting kEND Error detected while processing function importjs#ImportJSImport: line 1: NoMethodError: undefined methodimport' for nil:NilClass
Press ENTER or type command to continue

I'm going to look into it a bit and see if I can find the problem. Since this does not happen on my work laptop, I assume it is related to something in how my environment is set up.

@flarnie
Copy link
Contributor Author

flarnie commented Nov 28, 2014

On line 71 in import-js/ruby/import-js/importer.rb there are some method calls that are split onto separate lines. I assume my version of Ruby doesn't like that syntax - when I moved those methods all onto one line the error went away.

Edit: Support for newlines after method calls was added in Ruby 1.9 so my Vim installation must be using an old version of Ruby.

@trotzig Moving the placement of the dot makes this backwards compatible with old Ruby versions, like so:

70 string.
71 gsub(/::/, '/').
72 gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
73 gsub(/([a-z\d])([A-Z])/, '\1_\2').
74 tr('-', '_').
75 downcase

However, this Ruby styleguide recommends keeping the dot as the prefix rather than placing it at the end like this. I agree that the 1.9 syntax is more readable.

Options:

  • Update the README to expect users to have Ruby 1.9+ when using this plugin.
  • Move to the old syntax and support older versions of Ruby.

I'll submit pull requests for each option.

@flarnie
Copy link
Contributor Author

flarnie commented Nov 28, 2014

It looks like you can use the commands :echo has('ruby') and :ruby puts RUBY_VERSION to inspect whether Vim has Ruby set up and what version it's running.1

Mine is using '1.8.7' which is probably just the system default. I'm going to try and set it to one of the more recent versions.

@flarnie
Copy link
Contributor Author

flarnie commented Dec 2, 2014

Closed by 0cd733e

@trotzig trotzig closed this as completed Feb 11, 2015
trotzig pushed a commit that referenced this issue Jul 16, 2015
The package.json file of a node module can (and often does) contain a
`main` property pointing to the main module of a package. For instance,
the package.json of the `json-sass` package points to "lib/jsonSass.js".
To import json-sass, all you have to do is `require('json-sass')`.
Webpack and other node-compatible tools will figure out what file to
really look for based on the information in the package.json file.

There's one side-effect of how I implemented this behavior that I hope
to address soon: when multiple files resolve to a variable and one of
them is derived from the package.json file, you will see something like
this:

  [import-js]: Pick file to import for `Foo`:
  1. Foo/package.json
  2. bar/foo.js

It would be better if #1 said "Foo", or perhaps the entire path to the
Foo folder, "app/assets/components/Foo". I plan on tackling that later.

Fixes #27
@lencioni lencioni added the bug label Jan 8, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants