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

Allow imports of JSON #1065

Merged
merged 1 commit into from
Oct 31, 2018
Merged

Allow imports of JSON #1065

merged 1 commit into from
Oct 31, 2018

Conversation

kitsonk
Copy link
Contributor

@kitsonk kitsonk commented Oct 22, 2018

Fixes #1048

This is a WIP PR for allowing the import of JSON as a module, which would include the ability to ensure its type safety in consuming code. This would allow:

config.json

{
  "debug": true,
  "version": "1.0.0"
}

main.ts

import * as configJson from "./config.json";

if (configJson.debug === true) {
  console.log(`Version: ${configJson.version}`);
}

@kitsonk kitsonk mentioned this pull request Oct 22, 2018
3 tasks
@kitsonk kitsonk changed the title [WIP] Allow imports of JSON Allow imports of JSON Oct 29, 2018
@kitsonk
Copy link
Contributor Author

kitsonk commented Oct 29, 2018

@ry this is ready for review

@kitsonk kitsonk closed this Oct 29, 2018
@kitsonk kitsonk reopened this Oct 29, 2018
@kitsonk kitsonk mentioned this pull request Oct 29, 2018
Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Just a few comments-

js/compiler.ts Outdated Show resolved Hide resolved
js/compiler.ts Show resolved Hide resolved
js/compiler.ts Outdated Show resolved Hide resolved
js/compiler.ts Show resolved Hide resolved
js/compiler_test.ts Outdated Show resolved Hide resolved
@kitsonk
Copy link
Contributor Author

kitsonk commented Oct 31, 2018

@ry ready for review again

Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

assertEqual(deps && deps.length, 0);
assert(factory != null);
const factoryResult = factory();
assertEqual(factoryResult, { hello: "world", foo: "bar" });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. Thanks.

@ry ry merged commit 2422e52 into denoland:master Oct 31, 2018
ry added a commit to ry/deno that referenced this pull request Nov 2, 2018
Slowdowns cold-boot benchmark: 0.5s -> 0.8s

This reverts commit 2422e52.
ry added a commit to ry/deno that referenced this pull request Nov 5, 2018
- Performance and stability improvements on all platforms.
- Add repl (denoland#998)
- Add deno.Buffer (denoland#1121)
- Support cargo check (denoland#1128)
- Upgrade Rust crates and Flatbuffers. (denoland#1145, denoland#1127)
- Add helper to turn deno.Reader into async iterator (denoland#1130)
- Add ability to load JSON as modules (denoland#1065)
- Add deno.resources() (denoland#1119)
- Add application/x-typescript mime type support (denoland#1111)
@ry ry mentioned this pull request Nov 5, 2018
ry added a commit that referenced this pull request Nov 5, 2018
- Performance and stability improvements on all platforms.
- Add repl (#998)
- Add deno.Buffer (#1121)
- Support cargo check (#1128)
- Upgrade Rust crates and Flatbuffers. (#1145, #1127)
- Add helper to turn deno.Reader into async iterator (#1130)
- Add ability to load JSON as modules (#1065)
- Add deno.resources() (#1119)
- Add application/x-typescript mime type support (#1111)
@zekth
Copy link
Contributor

zekth commented Oct 12, 2019

import { version } from "./config.json";

console.log(`Version: ${version}`);

This output :

The requested module './config.json' does not provide an export named 'version'

Would it be possible to support it in the future?

@kitsonk kitsonk deleted the json-modules branch August 2, 2022 04:43
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.

Ability to import JSON
3 participants