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

Fix missing var declaration in arduino.js #2247

Merged
merged 1 commit into from Oct 31, 2019

Conversation

EricMCornelius
Copy link
Contributor

Fixes ARDUINO_KW is not defined errors when executing in strict mode.

Fix not defined errors in strict mode
@joshgoebel
Copy link
Member

@EricMCornelius Oops, that’s my code too. :(. Thanks!

@joshgoebel joshgoebel merged commit addd3cf into highlightjs:master Oct 31, 2019
@joshgoebel
Copy link
Member

What is the context that you are using the library where this came up?

@fdemello
Copy link

fdemello commented Nov 1, 2019

Just ran into this error on 9.16.1. When will there be a release with a fix?

import hljs from 'highlight.js'
        | ^

ReferenceError: ARDUINO_KW is not defined

@EricMCornelius
Copy link
Contributor Author

@yyyc514 - it's being incorporated by a webpack build for a cli tool I'm working on, and was throwing the error. Truth be told, I didn't dig in too much :)

@joshgoebel
Copy link
Member

Just ran into this error on 9.16.1. When will there be a release with a fix?

Did you trim some of the log there? Can you share how to reproduce the error you are seeing? ARDUINO_KW isn't even part of highlight.js itself, so I'm not sure why importing that file would give any error at all...

@joshgoebel
Copy link
Member

If there is some way to reproduce this with just node I'd love to know. So far testing with --experimental-modules, --use_strict, and "use strict" and including highlight.js, cpp, arduino... it all "just works".

test.mjs:

"use strict";

import hljs from './build/lib/highlight.js'
import cpp from "./build/lib/languages/cpp.js"
hljs.registerLanguage("cpp", cpp)
import arduino from "./build/lib/languages/arduino.js"
console.log(arduino(hljs).aliases)

@joshgoebel
Copy link
Member

And with rollup I can't even get started since we don't export anything by default:

1: "use strict";
2:
3: import hljs from './build/lib/highlight.js';
          ^
Error: 'default' is not exported by build/lib/highlight.js

@joshgoebel
Copy link
Member

Ok, if I use rollup and rollup-plugin-commonjs I can build a package that exhibits these issues and should be a good test case to prevent this sort of thing in the future. Trying to automate that testing now.

@EricMCornelius
Copy link
Contributor Author

@yyyc514 - sorry I didn't get back to you yesterday evening, but my webpack usage is quite complicated (is that redundant to state?) and wouldn't be easy to trim down to a base case.

That said, glad to hear you've already found a reproducible case via rollup. Really appreciate your work and this project!

joshgoebel added a commit to joshgoebel/highlight.js that referenced this pull request Nov 1, 2019
- Adds a test to the CI pipeline that builds a "typical" consolidated
  Highlight.js package from the full NPM source and then checks that
  that build actually executes without errors

Related to highlightjs#2247.
joshgoebel added a commit to joshgoebel/highlight.js that referenced this pull request Nov 1, 2019
- Adds a test to the CI pipeline that builds a "typical" consolidated
  Highlight.js package from the full NPM source and then checks that
  that build actually executes without errors

Related to highlightjs#2247.
joshgoebel pushed a commit that referenced this pull request Nov 1, 2019
- Fix “not defined” errors in strict mode for arduino.js
@joshgoebel
Copy link
Member

@fdemello Pushing 9.16.2 now.

@fdemello
Copy link

fdemello commented Nov 1, 2019

@yyyc514 I'll re-test with 9.16.2. I saw the error when our test suite executed.

$ npm run test
> react-scripts test --transformIgnorePatterns "node_modules/(?!mermaid)/" --env=jsdom
  ● Test suite failed to run

    ReferenceError: ARDUINO_KW is not defined

      1 | import React from 'react'
      2 | import Remarkable from 'remarkable'
    > 3 | import hljs from 'highlight.js'
        | ^
      4 | // project imports
      5 | import mermaid from 'mermaid'


      at language (node_modules/highlight.js/lib/languages/arduino.js:3:12)
      at Object.registerLanguage (node_modules/highlight.js/lib/highlight.js:887:34)
      at Object.<anonymous> (node_modules/highlight.js/lib/index.js:13:6)
      ... project specific lines
      at Object.<anonymous> (src/App.tsx:3:1)
      at Object.<anonymous> (src/__tests__/test.tsx:4:1)

joshgoebel added a commit that referenced this pull request Nov 5, 2019
- Adds a test to the CI pipeline that builds a "typical" consolidated
  Highlight.js package from the full NPM source and then checks that
  that build actually executes without errors

Related to #2247.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants